Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] Enhance cache busting customization

#5190

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:

RELEASE_NUMBER = 12345
config.action_controller.asset_path = proc { |asset_path|
  "/release-#{RELEASE_NUMBER}#{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|
  asset_path.clone.insert(-(File.extname(asset_path).length+1),"-#{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.

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:35 PM

  2. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:35 PM

  3. Richard Hulse
    Richard Hulse

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

    February 2nd, 2011 @ 06:03 PM