我使用带链轮的中间人将我的js和css文件打包成一个文件。这可以很好地工作。但我想知道是否有可能在中间人的链轮上启用指纹功能。
例如,我的文件all.js,其中的所有内容都被编译,被重命名为all-4e17d33ff76d744900c2691a71ed83e4.js。
如果图像也能做到这一点,那就太好了。
发布于 2012-11-21 16:26:11
我还没有找到一个开箱即用的解决方案,但我做了自己的解决方案。在config.rb中,我运行after_build钩子。不是最好的方法,但它是有效的:
after_build do
require 'fileutils'
delete_except "build/javascripts/", "all.js"
delete_except "build/stylesheets/", "all.css"
require 'digest/sha1'
sha1 = Digest::SHA1.hexdigest Time.now.getutc.to_i.to_s
allJS = "all-" + sha1 + ".js"
allCSS = "all-" + sha1 + ".css"
File.rename("build/javascripts/all.js", "build/javascripts/" + allJS)
File.rename("build/stylesheets/all.css", "build/stylesheets/" + allCSS)
index_file = "build/index.html"
html = File.read(index_file)
html = html.gsub(/all\.js/, allJS)
html = html.gsub(/all\.css/, allCSS)
File.open(index_file, "w") { |file| file.puts html }
end我正在做以下工作:
删除不必要的生成的散列,并根据时间(这对我来说就足够了)将散列附加到具有新文件名files
发布于 2012-12-11 05:28:13
使用
activate :asset_hash在您的中间人配置(Improving Cacheability)中。
(您将希望使用 :asset_hash或:cache_buster中的一个,而不是两者都使用。)
https://stackoverflow.com/questions/12662707
复制相似问题