栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何从Compass生成的Sprite图像文件名中删除哈希?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何从Compass生成的Sprite图像文件名中删除哈希?

不幸的是,该

asset_cache_buster :none
选项不会禁用将哈希添加到文件名的末尾。

就像我几天前用法语写的一样,Compass无法禁用缓存哈希无效,但是我提出了一个解决方案]。
在您的配置文件(例如

config.rb
)中,添加以下几行:

# 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')  endend# 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  endend

现在,用于

compass clean
删除生成的文件并使用重新启动编译
compass compile

您获取例如一个
images/icons-scb1e5456d5.png
文件
一个
images/icons.png
文件。在样式表中,所有对精灵的引用现在都指向没有哈希的版本。

确保保留文件中提供的哈希值,以优化Compass的编译时间。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/452007.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号