Streaming HTTP / Server Push

In an InfoWorld article, from last week, a mention of using streaming HTTP for advanced Web-based applications was made. There was barely any explanation of the technology and I imagine that some people don’t know how it works. I figured that I could pull together a couple examples to show people. The basic concept is such:

You create a CGI application (or a complete web server, dishing out dynamic content) which continually pushes mini-updates to a user’s browser. To acheive this, the connection between the user’s browser and the server must never be closed. For example, the normal HTTP process is: Request -> Data is Read From File -> Data is Sent to Browser -> Connection is Closed. One new way of doing it could be: Request -> (1) DB is checked for Updates -> Data is Sent to Browser -> Goto (1). Notice that the connection is never closed – this is important. Now, the ‘chunks’ of data that are being sent to the browser could exist in the form of Javascript chunks or even XML. Sounds simple enough, but the hassles are just beginning.

  • The most common way for streaming these items is through an IFrame which contains a page that is forever loading – which is seemingly ok, since it’s not the main user page. However, all major browsers will state that the page is still loading as long as the user is on the page. In my opinion, this is a rather large usability issue. Also, if a user does hit the stop button, all of the streaming content will be killed – unbeknownst to them.
  • The only way to get around this issue is to use a server push method using a multipart/x-mixed-replace header, which only works in Mozilla-based browsers. You’d think that something that’s a part of HTTP would be implemented across the board in all browsers, but not so.
  • Now, if you want to circumvent the use of an IFRAME, you could try using the multipart trick with XMLHTTPRequest (with server side) – which is cool, no doubt, but again doesn’t work in non-Mozilla-based browsers.
  • Oh, and while you’re testing – don’t open two streaming pages up in Firefox – it won’t work. Firefox thinks that the first page that you open is still loading and, therefore, should wait until the page is done loading to load the other one too.
  • And if you’re running this streaming app in a CGI application that’s behind Apache, be sure that you have GZIP compression turned off – if you don’t, Apache will wait until your entire page loads, in order to try compressing it, before sending it to the browser.

A couple points to consider:

  • ‘Typical’ AJAX appliations utilize XMLHTTPRequest doing single requests/updates. The next wave of web applications are going to have more streaming components included. This is going to be an essential portion of any new web application coming out.
  • There is very very little aggregated knowledge on the concept of streaming http, which makes development of this technology very hard.
  • This is all ironic because this technology has been around for much longer then the use of XMLHTTPRequest and yet is is used less then this ‘newer’ technology. Some of this can bee seen in a post by Matt Haughey about KnowNow using Streaming HTTP.

So, anyway: There needs to be more documentation and more use of Streaming HTTP / Server Push technology – if you don’t use it in your applications, someone else will, I can guarantee it.

Posted: June 5th, 2005


Subscribe for email updates

10 Comments (Show Comments)



Comments are closed.
Comments are automatically turned off two weeks after the original post. If you have a question concerning the content of this post, please feel free to contact me.


Secrets of the JavaScript Ninja

Secrets of the JS Ninja

Secret techniques of top JavaScript programmers. Published by Manning.

John Resig Twitter Updates

@jeresig / Mastodon

Infrequent, short, updates and links.