84 points · by ab9 · 15y ago · 33 comments
I've got ideas for handling exceptions, but I just can't make it happen for 3.1. :-(
It's going to be a tradeoff, either you accept that an exception can occur after sending a '200 OK' status code and possibly resort to javascript to display the error in a nice way, or you'll use the old fashioned way and send the correct response when the full page has loaded.
I'm going to use HTTP Streaming and rely on my tests and Hoptoad to fix errors as soon as they'll occur. I think the performance boost outweighs the consequence of not sending the correct status code when an exception occurs.
EDIT TO ADD: ok, so how does this work if you're page has js/jquery code executing on load? (say for js-based navigation and layouts) ... are people gonna see funky stuff before the page is fully loaded and the js is executed?
They won't do it for application/xhtml+xml, so if you want to see this in action, try sending your page as text/html and then application/xhtml+xml. You'll notice that the XML-based page seems glacial.
(Why does this happen? Who knows. I have been using streaming XML parsers since like 1990...)
But who cares? The browser isn't validating HTML as it's rendering it, otherwise the internet would be one big blank page.
On a slightly related note tuning these 3 values and setting them to sizes appropriate for the content you are serving can increase your webservers performance.
Using a simple CGI script, both methods achieve the same and work in FF and Chrome - chunks sent have their script statements executed, so you can e.g update a progress bar as you render partial content. However, I had trouble getting it to work with gzip; I had to turn off gzip (SetEnv no-gzip in .htaccess) otherwise the whole output was sent at once (this has possible to do with some default compression buffer size setting).
I wonder why "HTTP Streaming" (known since years as "Chunked Encoding") is such a big deal now.
The innovation is not what headers to send, it's to produce your data incrementally instead of all at once.
If you are simply streaming a stored video, you can just get the file size, use that as the content-length, and send the video. If the content is in a streamable format the client can just read/play the data as it is received. Chunked encoding will in fact add a little overhead to just sending as is.
Chunked encoding is more apt for situations where you don't know beforehand how much data you are going to send.
What they do is parallel-encode their video feed to many different bitrates, then as the client is keeping up or not keeping up with the incoming chunks they move up or down the scale of which chunks to send. The best part is, it works via existing http cdn's like level3 and akamai, so just about anybody can stream live video this way to as many people on the internet as they can get to watch it for the already commodity cost of cdn bandwidth.
[1] - http://arstechnica.com/apple/news/2011/04/adobe-throws-in-to...
See:
http://tools.ietf.org/html/draft-pantos-http-live-streaming-...