HTTP Streaming: Javascript in the head or at the bottom of the page?

There's a discussion going on at StackOverflow about whether, with the
advent of HTTP streaming in Rails 3.1, it's time to bend the rules
with respect to the time honoured tradition of putting <script> tags
before the closing </body> tag.

http://stackoverflow.com/questions/6116436/rails-3-1-http-streaming-js-in-head-or-bottom-of-body/6376719#6376719

Cheers,
Steven…

For the general case, I think unfortunately they are still going to go
to the bottom. Reason is Safari for Mac buffers 1024 bytes before it
starts to issue requests for assets (and Safari for iPhone and iPad
buffer 512 bytes).

Since the head of a document is typically smaller, Safari users would
still get the ordinary bad experience.

Firefox, Opera, and IE8 do not buffer, and Chrome buffers 252 bytes,
according to some test I've done together with Hongli Lai.

Has Rails changed the order in which it does things??

* instantiate a controller object and call the appropriate action method
* render a view (and its partials, etc)
* grab the layout and build the page by interpolating the various content_for bits and the main render content where there are yield's
* return the whole thing as the response

How can you get the <head> from the layout first? What if a 'yield :head_stuff' is encountered?

-Rob

P.S. I haven't played with 3.1 yet and wasn't at RailsConf to hear any related talks.

Rob Biedenharn
Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/
rab@GaslightSoftware.com http://GaslightSoftware.com/

That's still how things work in general.

But now you can also ask Rails to stream a certain action, or all
actions of a controller. In that case, a chunked response is produced
and the order of evaluation is different (think top-down). As you
anticipated this has implications, see

http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html