I noticed that some of my ajax-heavy sites (which I visit, and not the ones I created) have certain automatic update features. For example, in GMail, if I get a new message, I see a new message without reloading the page. The same thing happens with a browser-based IM client. From what I can say, there are no java applets handling browser-server bindings, so I can only assume that this is done by AJAX and possibly some element that I don’t know about. Therefore, in my opinion, this is done in one of two ways:
javascript does a persistent ping on the server side script, checking for any updates that might be available (which explains why some of these pages bring any other pages of increased complexity to bypass). or
javascript is sitting idle, and the server side of the script actually pushes any updates to the browser. But I'm not sure if this is possible. I would suggest that there is some kind of AJAX function that still works, but all this just asks “any updates”? and the server script has a simple boolean expression that says "nope" or "I'm glad you asked." But if so, any data changes should have called the script directly so that they are ready for data changes and made changes to this logical function.
So maybe / maybe / how does it work? I imagine something like:
Someone sends an email / IM / DB update to the server, the server calls the script using the script URL plus some corresponding GET variable, the script marks this change and updates the "available updates" variable, AJAX gets the answer that there really is updates, AJAX performs its usual function of an “update page”, which executes ordinary update scripts and displays them in a browser.
I ask because it seems really inefficient that js just does a constant check that requires: a) the server to work every 1.5 seconds, and b) my browser should work every 1.5 seconds, so at my end I can say: "Oh boy, I have IM! just like a real IM client!"
ajax asynchronous server-side server-push
Anthony
source share