Rails 4 Asset Pipeline:无论有没有指纹都可以编译 [英] Rails 4 Asset Pipeline: Compile both with and without fingerprint
问题描述
第4轨更改了对资产进行指纹识别的方式(用于清除浏览器缓存):
Rails 4 has changed the way assets are fingerprinted (for browser cache busting):
Old Strategy: application.css?12345
Rails 3.2: application-12345.css and application.css
Rails 4.0: application-12345.css
尽管这很合理,但是如果样式表被其他服务(在我们的示例中为Zendesk)使用,则是一个问题.这个外部站点需要Rails应用程序中的CSS,但是它不知道指纹(即摘要).
While this makes perfect sense, it's a problem if the stylesheets are used by another service (in our case Zendesk). This external site needs the CSS from the Rails app, but it doesn't know the fingerprint (aka: digest).
有没有办法编译带有或不带有指纹的所有资产?或者也许是另一种解决此问题的方法?
Is there a way to compile all assets both with and without fingerprint? Or maybe another approach to tackle this?
推荐答案
我已经编写了一个rake任务,以获取Rails 3.2的未指纹文件:
I've written a rake task to get the un-fingerprinted files à la Rails 3.2 back:
namespace :assets do
desc "Create symlinks without cache busting digest"
task :create_symlinks_without_digest => :environment do
Dir.glob(Rails.root.join('public', 'assets', '**', '*')).each do |item|
if File.file?(item) && item.match(/-[a-f0-9]{32}/)
FileUtils.ln_s Pathname(item).basename, item.sub(/-[a-f0-9]{32}/, '')
end
end
end
end
这篇关于Rails 4 Asset Pipeline:无论有没有指纹都可以编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!