Rails 4.2 Rails.application.config.assets.version不会使摘要资产文件名无效 [英] Rails 4.2 Rails.application.config.assets.version doesn't invalidate digest asset file names
问题描述
我有一个Rails 4.2.4(Ruby 2.2.2)应用程序,并且正在通过Cloudfront提供静态资产.
I have a Rails 4.2.4 (Ruby 2.2.2) application and I am serving static assets via Cloudfront.
如果Cloudfront正在提供您不想要的服务,则有两种可能性:
If Cloudfront is serving something you don't want, there are two possibilities:
- 使Cloudfront中的内容无效或
- 更改所投放资产的名称
但是,当我更改
Rails.application.config.assets.version ='1.0'
Rails.application.config.assets.version = '1.0'
到
Rails.application.config.assets.version ='2.0'
Rails.application.config.assets.version = '2.0'
(在config/initializers/assets.rb中)
(in config/initializers/assets.rb)
和
-
删除公共/资产中的所有资产
delete all the assets in public/assets
运行"RAILS_ENV =分段执行exec rake资产:预编译"
run "RAILS_ENV=staging bundle exec rake assets:precompile"
生成相同的文件名!
我发现唯一使application.scss的摘要文件无效的方法是添加一些虚拟内容,以引起新的md5校验和.
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.
我在做什么错了?
不是新资产.版本会更改摘要文件的名称吗?
Shouldn't a new assets.version change the digested file names?
最诚挚的问候和感谢!
推荐答案
根据我打开的Rails拉取请求中的注释,这是需要修复的回归:
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
更新:如sansarp所述,该github问题中列出的解决方法之一是使用链轮的旧版本:
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"
这篇关于Rails 4.2 Rails.application.config.assets.version不会使摘要资产文件名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!