I am trying to make a refresh algorithm for my site but dont want to have a bunch of $.post()
scripts being sent to the server checking for updates. So I was wondering if there were any good ways of sending updates to the page that is being viewed when something on a database is changed.

- 792
- 2
- 8
- 24
-
Just cause there is no question mark does not mean that its not a question.... – Noah Passalacqua Oct 06 '12 at 23:04
2 Answers
You can use html5 web-sockets
You need a server, P2P doesn't work yet between browsers. See: Do I need a server to use HTML5's WebSockets?
Websocket (HTML5 sockets) is a way to have a bi-directional open connection between the browser and your server. Otherwise you'll have to work using XHR (aka Ajax) which is pull only. Mozilla wrote a great article explaining how they built: BrowserQuest (or just play it: http://browserquest.mozilla.org/)
Alternatives are generally based on Flash XMLSocket!

- 1
- 1

- 5,253
- 4
- 23
- 45
The common way to do it is called Comet.
Basically, you create an XMLHttpRequest
, send it to the server and wait. The server keeps the connection open, and sends data then closes it each time something happens server-side. It can also send nothing and close every 30 seconds or so to clean up things a bit.
WebSockets are a rather new technology, and it will be the way to go in the future, but I encourage you to use Comet right now, unless you want to play with something that's a little on the bleeding-edge side of web developement.

- 6,809
- 3
- 49
- 71