css – 如何从指南针生成的精灵图像文件名中删除哈希?

前端之家收集整理的这篇文章主要介绍了css – 如何从指南针生成的精灵图像文件名中删除哈希?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
指南针使用chunky_png渲染精灵.它向文件的末尾添加一个哈希值,以强制缓存下载新的图像精灵.有没有办法把这个缓存关闭

解决方法

不幸的是,asset_cache_buster:none选项不禁止将哈希添加文件名的末尾.

就像我之前写的(法语),Compass没有办法禁用缓存哈希破解,但是我建议a solution.
在您的配置文件(例如config.rb)中添加以下行:

@H_404_9@# Make a copy of sprites with a name that has no uniqueness of the hash. on_sprite_saved do |filename| if File.exists?(filename) FileUtils.cp filename,filename.gsub(%r{-s[a-z0-9]{10}\.png$},'.png') end end # Replace in stylesheets generated references to sprites # by their counterparts without the hash uniqueness. on_stylesheet_saved do |filename| if File.exists?(filename) css = File.read filename File.open(filename,'w+') do |f| f << css.gsub(%r{-s[a-z0-9]{10}\.png},'.png') end end end

现在,使用指南针清除删除生成文件,并使用罗盘编译重新启动编译.
您可以获取例如images / icons-scb1e5456d5.png文件和images / icons.png文件.在样式表中,所有对sprite的引用现在都指向没有哈希的版本.

确保文件具有提供的哈希值,以通过Compass优化编译时间.

猜你在找的CSS相关文章