Several fixes for AC::Streaming
This commit is contained in:
parent
0258cc4d8a
commit
766564f78f
@ -9,22 +9,17 @@ module ActionController # :nodoc:
|
|||||||
# and then the layout. The response is sent to the client after the whole
|
# and then the layout. The response is sent to the client after the whole
|
||||||
# template is rendered, all queries are made, and the layout is processed.
|
# template is rendered, all queries are made, and the layout is processed.
|
||||||
#
|
#
|
||||||
# Streaming inverts the rendering flow by rendering the layout first and
|
# \Streaming inverts the rendering flow by rendering the layout first and
|
||||||
# streaming each part of the layout as they are processed. This allows the
|
# subsequently each part of the layout as they are processed. This allows the
|
||||||
# header of the HTML (which is usually in the layout) to be streamed back
|
# header of the HTML (which is usually in the layout) to be streamed back
|
||||||
# to client very quickly, allowing JavaScripts and stylesheets to be loaded
|
# to client very quickly, enabling JavaScripts and stylesheets to be loaded
|
||||||
# earlier than usual.
|
# earlier than usual.
|
||||||
#
|
#
|
||||||
# This approach was introduced in Rails 3.1 and is still improving. Several
|
# Several Rack middlewares may not work and you need to be careful when streaming.
|
||||||
# Rack middlewares may not work and you need to be careful when streaming.
|
# This is covered in more detail below, see the "Middlewares" section.
|
||||||
# Those points are going to be addressed soon.
|
|
||||||
#
|
#
|
||||||
# In order to use streaming, you will need to use a Ruby version that
|
# \Streaming can be added to a given template easily, all you need to do is
|
||||||
# supports fibers (fibers are supported since version 1.9.2 of the main
|
# to pass the +:stream+ option to +render+.
|
||||||
# Ruby implementation).
|
|
||||||
#
|
|
||||||
# Streaming can be added to a given template easily, all you need to do is
|
|
||||||
# to pass the +:stream+ option.
|
|
||||||
#
|
#
|
||||||
# class PostsController
|
# class PostsController
|
||||||
# def index
|
# def index
|
||||||
@ -35,7 +30,7 @@ module ActionController # :nodoc:
|
|||||||
#
|
#
|
||||||
# == When to use streaming
|
# == When to use streaming
|
||||||
#
|
#
|
||||||
# Streaming may be considered to be overkill for lightweight actions like
|
# \Streaming may be considered to be overkill for lightweight actions like
|
||||||
# +new+ or +edit+. The real benefit of streaming is on expensive actions
|
# +new+ or +edit+. The real benefit of streaming is on expensive actions
|
||||||
# that, for example, do a lot of queries on the database.
|
# that, for example, do a lot of queries on the database.
|
||||||
#
|
#
|
||||||
@ -59,7 +54,7 @@ module ActionController # :nodoc:
|
|||||||
# render stream: true
|
# render stream: true
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# Notice that +:stream+ only works with templates. Rendering +:json+
|
# Notice that +:stream+ only works with templates. \Rendering +:json+
|
||||||
# or +:xml+ with +:stream+ won't work.
|
# or +:xml+ with +:stream+ won't work.
|
||||||
#
|
#
|
||||||
# == Communication between layout and template
|
# == Communication between layout and template
|
||||||
@ -112,7 +107,7 @@ module ActionController # :nodoc:
|
|||||||
# This means that, if you have <code>yield :title</code> in your layout
|
# This means that, if you have <code>yield :title</code> in your layout
|
||||||
# and you want to use streaming, you would have to render the whole template
|
# and you want to use streaming, you would have to render the whole template
|
||||||
# (and eventually trigger all queries) before streaming the title and all
|
# (and eventually trigger all queries) before streaming the title and all
|
||||||
# assets, which kills the purpose of streaming. For this purpose, you can use
|
# assets, which defeats the purpose of streaming. Alternatively, you can use
|
||||||
# a helper called +provide+ that does the same as +content_for+ but tells the
|
# a helper called +provide+ that does the same as +content_for+ but tells the
|
||||||
# layout to stop searching for other entries and continue rendering.
|
# layout to stop searching for other entries and continue rendering.
|
||||||
#
|
#
|
||||||
@ -122,7 +117,7 @@ module ActionController # :nodoc:
|
|||||||
# Hello
|
# Hello
|
||||||
# <%= content_for :title, " page" %>
|
# <%= content_for :title, " page" %>
|
||||||
#
|
#
|
||||||
# Giving:
|
# Resulting in:
|
||||||
#
|
#
|
||||||
# <html>
|
# <html>
|
||||||
# <head><title>Main</title></head>
|
# <head><title>Main</title></head>
|
||||||
@ -132,6 +127,8 @@ module ActionController # :nodoc:
|
|||||||
# That said, when streaming, you need to properly check your templates
|
# That said, when streaming, you need to properly check your templates
|
||||||
# and choose when to use +provide+ and +content_for+.
|
# and choose when to use +provide+ and +content_for+.
|
||||||
#
|
#
|
||||||
|
# See also ActionView::Helpers::CaptureHelper for more information.
|
||||||
|
#
|
||||||
# == Headers, cookies, session, and flash
|
# == Headers, cookies, session, and flash
|
||||||
#
|
#
|
||||||
# When streaming, the HTTP headers are sent to the client right before
|
# When streaming, the HTTP headers are sent to the client right before
|
||||||
@ -161,9 +158,9 @@ module ActionController # :nodoc:
|
|||||||
#
|
#
|
||||||
# "><script>window.location = "/500.html"</script></html>
|
# "><script>window.location = "/500.html"</script></html>
|
||||||
#
|
#
|
||||||
# The first two characters (">) are required in case the exception happens
|
# The first two characters (<tt>"></tt>) are required in case the exception
|
||||||
# while rendering attributes for a given tag. You can check the real cause
|
# happens while rendering attributes for a given tag. You can check the real
|
||||||
# for the exception in your logger.
|
# cause for the exception in your logger.
|
||||||
#
|
#
|
||||||
# == Web server support
|
# == Web server support
|
||||||
#
|
#
|
||||||
@ -183,11 +180,13 @@ module ActionController # :nodoc:
|
|||||||
# unicorn_rails --config-file unicorn.config.rb
|
# unicorn_rails --config-file unicorn.config.rb
|
||||||
#
|
#
|
||||||
# You may also want to configure other parameters like <tt>:tcp_nodelay</tt>.
|
# You may also want to configure other parameters like <tt>:tcp_nodelay</tt>.
|
||||||
|
#
|
||||||
# Please check its documentation for more information:
|
# Please check its documentation for more information:
|
||||||
# https://bogomips.org/unicorn/Unicorn/Configurator.html#method-i-listen
|
#
|
||||||
|
# * https://bogomips.org/unicorn/Unicorn/Configurator.html#method-i-listen
|
||||||
#
|
#
|
||||||
# If you are using Unicorn with NGINX, you may need to tweak NGINX.
|
# If you are using Unicorn with NGINX, you may need to tweak NGINX.
|
||||||
# Streaming should work out of the box on Rainbows.
|
# \Streaming should work out of the box on Rainbows.
|
||||||
#
|
#
|
||||||
# ==== Passenger
|
# ==== Passenger
|
||||||
#
|
#
|
||||||
@ -203,7 +202,8 @@ module ActionController # :nodoc:
|
|||||||
# the response back to the client.
|
# the response back to the client.
|
||||||
#
|
#
|
||||||
# Please check the documentation for more information:
|
# Please check the documentation for more information:
|
||||||
# https://www.phusionpassenger.com/docs/references/config_reference/nginx/#passenger_buffer_response
|
#
|
||||||
|
# * https://www.phusionpassenger.com/docs/references/config_reference/nginx/#passenger_buffer_response
|
||||||
#
|
#
|
||||||
module Streaming
|
module Streaming
|
||||||
private
|
private
|
||||||
|
Loading…
Reference in New Issue
Block a user