Wednesday, May 24th, 2006
More and more, Ajax apps are using various techniques to keep content fresh in the browser. Essentially, we’re talking about reversing the usual communication flow- the server notices something’s happened, and wants to tell the browser about it. Server “calls” browser, not browser calls server.
The popular Java Ajax framework, DWR, recently released milestone 2 towards a 2.0 release, and introduced the term “Reverse Ajax” in the process, to capture this high-level pattern. This article (via Joe Walker) abstracts the communication details behind a clean API, so you can easily switch between three different implementations of Reverse Ajax:
1. Polling: This is where the browser makes a request of the server at regular and frequent intervals, say every 3 seconds to see if there has been an update to the page. To illustrate imagine a 5 year old (or a donkey) in the back of the car shouting ‘are we there yet?’ every few seconds and you get the picture.
2. Comet, long lived Http, or the slow load technique: Are all names for the same thing. As already mentioned, the server has to wait for the browser to make contact. But this technique allows the server to start answering the browser’s request for information very slowly. Extremely slowly. Actually in the same way I used to answer my French teachers at school, it starts the reply but never actually finishes. This allows the server to keep a communications channel open (unlike me and my French teacher) to pass down additional information when the time comes. The closest we currently get to a server push. See Alex Russell’s article for the coining of the phrase and outline of definition of Comet. See Bryce Nesbitt’s for a brief description and simple demo of slow-load.
3. PiggyBack Technique: Here the server, having an update to send, waits for the next time the browser asks it a question and… pounce, sends the answer and the update. This technique is well understood in long term relationships and is usually preceded by ‘and another thing.’ You know, you ask what you thought was a straight forward question and get a lot more than you bargained for.
Posted by Michael Mahemoff at 4:38 pm