When your templates change, browser caches bust automatically. #16527

Merged
merged 1 commit into from Aug 17, 2014

Conversation

Projects
None yet
4 participants
@jeremy
Member

jeremy commented Aug 16, 2014

New default: the template digest is automatically included in your ETags.
When you call fresh_when @post, the digest for posts/show.html.erb
is mixed in so future changes to the HTML will blow HTTP caches for you.
This makes it easy to HTTP-cache many more of your actions.

If you render a different template, you can now pass the :template
option to include its digest instead:

  fresh_when @post, template: 'widgets/show'

Pass template: false to skip the lookup. To turn this off entirely, set:

  config.action_controller.etag_with_template_digest = false
@dhh

This comment has been minimized.

Show comment
Hide comment
@dhh

dhh Aug 16, 2014

Member

Looks good to me 👍

Member

dhh commented Aug 16, 2014

Looks good to me 👍

+ class_attribute :etag_with_template_digest
+ self.etag_with_template_digest = true
+
+ ActiveSupport.on_load :action_view, yield: true do |action_view_base|

This comment has been minimized.

@carlosantoniodasilva

carlosantoniodasilva Aug 16, 2014

Member

No need for the block arg?

@carlosantoniodasilva

carlosantoniodasilva Aug 16, 2014

Member

No need for the block arg?

This comment has been minimized.

@jeremy

jeremy Aug 17, 2014

Member

Yeah - included it to make it clear that we aren't using the instance_eval form of on_load. We're being called like a normal block.

@jeremy

jeremy Aug 17, 2014

Member

Yeah - included it to make it clear that we aren't using the instance_eval form of on_load. We're being called like a normal block.

+ # * <tt>:template</tt> By default, the template digest for the current
+ # controller/action is included in ETags. If the action renders a
+ # different template, you can include its digest instead. If the action
+ # doesn't render a template at all, you can pass +template: false+ to

This comment has been minimized.

@robin850

robin850 Aug 17, 2014

Member

With RDoc 4.1.1, the given snippet won't be parsed wrapped between pluses, you'll need to rely on <tt>:

$ echo "+template: false+" | rdoc --pipe

<p>+template: false+</p>

$ echo "<tt>template: false</tt>" | rdoc --pipe

<p><code>template: false</code></p>

Great work so far ! :-)

@robin850

robin850 Aug 17, 2014

Member

With RDoc 4.1.1, the given snippet won't be parsed wrapped between pluses, you'll need to rely on <tt>:

$ echo "+template: false+" | rdoc --pipe

<p>+template: false+</p>

$ echo "<tt>template: false</tt>" | rdoc --pipe

<p><code>template: false</code></p>

Great work so far ! :-)

This comment has been minimized.

@jeremy

jeremy Aug 17, 2014

Member

Fixed - thanks!

@jeremy

jeremy Aug 17, 2014

Member

Fixed - thanks!

@robin850 robin850 added this to the 4.2.0 milestone Aug 17, 2014

When your templates change, browser caches bust automatically.
New default: the template digest is automatically included in your ETags.
When you call `fresh_when @post`, the digest for `posts/show.html.erb`
is mixed in so future changes to the HTML will blow HTTP caches for you.
This makes it easy to HTTP-cache many more of your actions.

If you render a different template, you can now pass the `:template`
option to include its digest instead:

  fresh_when @post, template: 'widgets/show'

Pass `template: false` to skip the lookup. To turn this off entirely, set:

  config.action_controller.etag_with_template_digest = false

jeremy added a commit that referenced this pull request Aug 17, 2014

Merge pull request #16527 from jeremy/etag_with_template_digest
When your templates change, browser caches bust automatically.

@jeremy jeremy merged commit a08ca4a into rails:master Aug 17, 2014

1 check was pending

continuous-integration/travis-ci The Travis CI build is in progress
Details

@jeremy jeremy deleted the jeremy:etag_with_template_digest branch Aug 17, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment