📎 Webclip
Forgotten Rails features: HTTP Streaming
HTTP streaming in Rails sends the response in chunks, with the layout head sent before the rest of the page. The post says this does not reduce generation time, but it can make pages appear to load faster by letting the browser request assets sooner.
Reading notes#
- HTTP streaming was added in Rails 3.1 and is described as a niche feature.
- The old
streammethod is gone; the post showsstream: truepassed torenderorrespond_with. - Using delayed query execution, such as
Project.scopedinstead ofProject.all, can make the header return faster. - NewRelic browser monitoring can block the response unless
auto_instrumentis set to false. - Action caching should not be used with streaming because it can cache chunk byte counts on the page.
- HAML does not work with HTTP streaming in the version mentioned, while Slim and ERB do.
content_forwill not work because the layout is sent before the view;provideis the suggested alternative.- The post recommends putting JavaScript include tags in the
headso the browser can load them while chunks arrive. - The author uses Unicorn for streaming and includes a sample Unicorn config for Heroku.
- The feature is used on the homepage and search results page for Days Out Near Me because those pages benefit most from faster perceived loading.
