13

I couldn't find the clear answer to this question in the docs. Many references just say that "changing the version invalidates the assets". Well, then isn't the same done by the fingerprinting mechanism, which generates hash tags based on file contents and names? Does anyone know what exactly config.assets.version is for?

Yevgeniy
  • 1,313
  • 2
  • 13
  • 26
  • 2
    http://stackoverflow.com/questions/13171647/what-does-changing-config-assets-version-number-do – deefour Apr 24 '13 at 01:38

1 Answers1

9

config.assets.version is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled.*

This can be helpful when the asset content hasn't changed, but you want to change the response headers served with the asset, but those headers are cached somewhere like a CDN or user's browser.

Changing your assets version will allow you to regenerate all of your assets with new md5 hashes, allowing you to serve up the same assets to your CDN with new headers.

*From RailsGuides - Configuring Rails Applications

NOTE: As of 20th May 2016, this feature does appear to have been broken for some time https://github.com/rails/sprockets-rails/issues/240. An alternative is to change the value of Rails.application.config.assets.prefix instead.

James P McGrath
  • 1,856
  • 1
  • 20
  • 35
  • Hopefully they fix this issue soon. It's simply not an option to ask user's to make sure they reset their history before viewing the site to see changes lol – bkunzi01 Oct 03 '16 at 13:54
  • @bkunzi01 did you see my note on the alternative method to bust your assets with long expiry dates? – James P McGrath Oct 04 '16 at 08:01
  • Good tip! When you do that, do you need to delete the original public/assets folder or will it automagically precomp. to a new folder and steer clear of the old assets? – bkunzi01 Oct 04 '16 at 11:48
  • It wouldn't hurt to `rake assets:clobber` beforehand, but it's not 100% necessary as your generated view html and css will reference asset files with a new prefix in the path, making the old assets effectively invisible to regular users. – James P McGrath Oct 07 '16 at 07:04