Rails 4.2 Rails.application.config.assets.version doesn't invalidate digest asset file names

怎甘沉沦 提交于 2019-12-30 16:50:20

问题


I have a Rails 4.2.4 (Ruby 2.2.2) application and I am serving static assets via Cloudfront.

If Cloudfront is serving something you don't want, there are two possibilities:

  • Invalidate the content in Cloudfront or
  • Change the name of the asset served

However, when i change

Rails.application.config.assets.version = '1.0'

to

Rails.application.config.assets.version = '2.0'

(in config/initializers/assets.rb)

and

  • delete all the assets in public/assets

  • run "RAILS_ENV=staging bundle exec rake assets:precompile"

the same file names are generated!

The only way i found to invalidate the digested file of application.scss was to add some dummy content in order to provoke a new md5 checksum.

What am i doing wrong?

Shouldn't a new assets.version change the digested file names?

Best Regards and thanx!


回答1:


As per the comments in the Rails pull request I opened, this is a regression that needs to be fixed: https://github.com/rails/sprockets-rails/issues/240

Update: As sansarp mentions, one of the workarounds listed in that github issue is to use an old version of sprockets:

gem 'sprockets', '< 3.0.0'

Another workaround is to use the asset path as a cache breaker instead:

# config/initializers/assets.rb
Rails.application.config.assets.prefix = "/assets/v1"



回答2:


Using sprockets of previous version could help you to get file names as expected. gem 'sprockets', '< 3.0.0' https://github.com/rails/sprockets




回答3:


If you use capistrano for deployment be sure to set assets_prefix in the deploy.rb file.

set :assets_prefix, "assets/v1"


来源:https://stackoverflow.com/questions/32548755/rails-4-2-rails-application-config-assets-version-doesnt-invalidate-digest-asse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!