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 tags
before the closing tag.

Cheers,
Steven

On Thu, Jun 16, 2011 at 8:45 PM, steveluscher [email protected]
wrote:

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 tags
before the closing tag.

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

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 L…

On Jun 16, 2011, at 3:00 PM, Xavier N. wrote:

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 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 B.
[email protected] http://AgileConsultingLLC.com/
[email protected] http://GaslightSoftware.com/

On Thu, Jun 16, 2011 at 9:10 PM, Rob B.
[email protected] wrote:

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 from the layout first? What if a ‘yield
:head_stuff’ is encountered?

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs