Monthly Archives: August 2009

AJAX and COMET, Titans Falling

In the world of web technologies when one giant falls–another rises in its place. Asynchronous Javascript And Xhtml, the infamous hack that invented Web 2.0, has proved very useful for dynamically updating the content of web pages without the viewer having to refresh the page. We have all become addicted to and very familiar with AJAX at this point, so I will not delve into an explanation of what it is, but rather on its shortcomings.

AJAX depends upon user input or timers to know when to ask for content from the server. Like a sidekick in the world of heros, AJAX stands on the sidelines, waiting for a signal to deliver what the viewer on the webpage needs to accomplish his task. The AJAX hack cannot mutate the aging fabric of the HTTP protocol itself. It can only exploit the request-then-deliver model of data transfer provided through HTTP.

Now, COMET is both an excellent soap powder and a term coined by Alex Russell in 2006 for an alternative to AJAX. The concept itself is no novelty, so as you can imagine it was around long before Russell. COMET is a “request” to a web page that keeps delivering content whether or not there is an actual renewed request for it by the user. It is a server force-feeding you data whether you are hungry for it or not.

That approach may sound like a bandwidth drain–and in truth, it often is–but it’s exactly what makes COMET superior in many ways to AJAX. It can do everything AJAX does, but only better. If you’re on your Facebook home page, where your friends’ feeds are being aggregated before your staring eyes, COMET would allow the feed to update as soon as a friend changes his status, as opposed to after 15 seconds, when AJAX checks to see if anyone has.

The only real flaw in COMET is in its implementation. Like AJAX, COMET is a hack. It is often implemented through tacky and dangerous means such as using iframes or script tags to keep an open connection to the server. Take a look at the wiki article, where you can read of many home-baked schemes to deliver COMET. This is why both COMET and its sidekick, AJAX, are about to fall.

The W3C has drafted a new specification called Web Sockets to address COMET and AJAX. Web Sockets is its own protocol ( ws:// ) distinct from ( http:// ) designed for interaction between web pages and server processes. It is an integral part of the emerging HTML5 spec being developed by W3C. The Web Sockets protocol will standardize COMET/AJAX code and simplify it massively for web developers, once it is implemented across major browsers. So in a sense, COMET and AJAX are about to die. They are collective terms for hacks of the HTTP protocol, which Web Sockets, through its very own protocol, is about to make unnecessary.

The ability to stream data from a server to a webpage, both ways, and practically from a page in one person’s browser to one in another, is slowly being realized through this new specification. Through this ability, the web will finally become “real-time.”