Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does config.assets.version do in Rails?

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?

like image 517
Yevgeniy Avatar asked Dec 14 '12 05:12

Yevgeniy


1 Answers

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.

like image 86
James P McGrath Avatar answered Dec 04 '22 19:12

James P McGrath