Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I change the format of Rails asset_tag URLs?
    primarykey
    data
    text
    <p><strong>Background</strong></p> <p>I'm currently working on a Rails 3 project that I intend to use with Amazon CloudFront with a custom origin pointing back to my actual web server. This means that my web server will tell the browser to retrieve static assets from CloudFront, if CloudFront has the asset cached it will return it, if it does not it will retrieve it using the same path from my web server and then cache it for future requests.</p> <p><strong>Problem</strong></p> <p>Amazon CloudFront drops and ignores query string parameters when determining whether it should bust it's own cache to re-download the asset from it's origin. This obviously poses a problem with the way Rails generates URLs with the <code>RAILS_ASSET_ID</code> which is to do: <code>/assets/path/to/asset.ext?RAILS_ASSET_ID</code>. With the default asset URLs CloudFront will hold onto stale assets for up to 24 hours.</p> <p><strong>Solution?</strong></p> <p>What I'm hoping to do is somehow override the way Rails 3 generates asset tags so that I can generate URLs like <code>/assets/RAILS_ASSET_ID/path/to/asset.ext</code>. I already have a solution for how to make the web server respond to those URLs, I just need to figure out how to make Rails generate the URL.</p> <p><strong>Notes</strong></p> <ol> <li>My <code>RAILS_ASSET_ID</code> will be a sub-string of my latest git commit hash. Setting this will be handled by capistrano during the deployment process. <strong>I am OK with busting all asset caches on each deployment, I don't need asset-specific IDs</strong></li> <li>I have already attempted to override <code>ActionView::Helpers::AssetTagHelper.rewrite_asset_path</code> but it didn't seem to work and from what I read this is a private method that should not be relied upon.</li> <li>Thank you in advance!</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload