Why HTTP Streaming?
weblog.rubyonrails.org
weblog.rubyonrails.org
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.
I've got ideas for handling exceptions, but I just can't make it happen for 3.1. :-(
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?
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.
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.
But that's the big difference isn't it? Browsers fix html as they go, but they blow up on XML (as mandated by the XML spec).
What would be weirder, seeing the page either render fully or blow up, or seeing a page start rendering and then at some point be replaced by an error message?
Of course ideally it would start rendering and keep rendering, never blowing up, but that's not really allowed in XML.
Who says the page has to be replaced? Webkit and Opera (IIRC) happily render the page up to the first error that they encounter.
Gecko's decision to do the YSOD was a bad one.
That shocks me quite a bit. This definitely didn't use to be the case for Safari, early versions implemented draconian XML error handling and refused to display non-well-formed documents.
> Gecko's decision to do the YSOD was a bad one.
Meh.
> Meh.
There were many circumstances that prevented the adoption of XHTML-as-XHTML. One of them was the fact that your users would get a cryptic error page, with no context, if something went wrong.
What Webkit does is much less threatening.
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-...