In Rails 3.1 there’s the option to enable HTTP streaming so that your page can be brought down in chunks. In the Railscast on this feature, Ryan recommended that it would be a good idea to enable this so that your CSS and JavaScript can be pulled down while the rest of your page is still being rendered.
I’ve always followed the guideline that scripts should be at the bottom of the page after all the page content is loaded so that it would reduce perceived loading time, but by doing this it won’t be taking advantage of the HTTP streaming.
What do you think is the best practice now?
I think this is an excellent question; one for which I felt compelled to Google for an answer.
The argument for putting script assets at the bottom of the page was to prevent blocking a browser’s renderer that could otherwise be painting pixels on the screen to keep the user busy while the rest of the page’s functionality loaded. With HTTP streaming, we’re talking about being able to do something about the server being the bottleneck. While we wait for all those expensive database queries and backend service calls to finish, we can load JS/CSS assets.
It seems to me that there’s a tipping point around which you should <head> your assets or not <head> your assets. This is only a net performance gain if your JS/CSS assets can be downloaded before your server has the rest of the response ready.
Don’t <head> a page’s assets if:
Do <head> a page’s assets if:
Does that sound about right?