This project is archived and is in readonly mode.

#5190 ✓stale
Richard Hulse

[PATCH] Enhance cache busting customization

Reported by Richard Hulse | July 24th, 2010 @ 05:40 AM

The current Rails cache busting regime (in ActionView::Helpers) gives you three options:

  1. asset_path + mtime query string (The default)
  2. RAILS_ASSET_ID environment variable used in place of mtime
  3. A proc called on config.action_controller.asset_path

The proc receives the asset_path, and the user can prepend a directory name (for example) for each release so that remote caches refetch the asset:

config.action_controller.asset_path = proc { |asset_path|
This patch also passes in the asset_id to the proc (using the internal asset_id caching mechanism), allowing the user to insert the mtime into the filename:
config.action_controller.asset_path = proc { |asset_path, asset_id|

This is the optimal regime for single server deployments (and those where the mtime can be synchronized between servers) because only assets that are actually modified will be refetched by the client browser or intermediate cache. On a site with many static assets and unique browsers this will reduce massive traffic spikes after a deployment.

The alternative is for the user to override ActionView::Helpers.rewrite_asset_path, but they would also have to handle the different Rails environments.

The submitted approach avoids having to to do this by extending the current method of altering the asset_path as a config option.

I have added tests and updated the documentation in the helper module.

Comments and changes to this ticket

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:35 PM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:35 PM

    • State changed from “open” to “stale”
  • Richard Hulse

    Richard Hulse February 2nd, 2011 @ 06:03 PM

    Should I check this against Rails 3.03 to get things moving ?

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket