gpt4 book ai didi

css - sass缓存破坏

转载 作者:太空宇宙 更新时间:2023-11-03 16:34:55 25 4
gpt4 key购买 nike

有没有办法在 SASS 中清除文件 rev 缓存?似乎可以根据此答案在此处使用指南针: SASS Image CSS Cache Busting (via Compass)

但我还没有找到任何方法来仅使用 SASS 来做到这一点。有没有办法让 SASS 从文件系统获取文件修改信息,并附加到图像路径?

而且我宁愿不附加查询字符串 - 相反,我认为这是一种更好的方法。

最佳答案

感谢 Dawn 这么久以来的插话!我已经弄明白了,但忘了我在这里发布了它。

我有一个自定义的 rb 文件,当我通过命令行运行 sass 时我会引用它 - 就像这样:

sass --update sass:css -r file_mod.rb

在 file_mod.rb 中,我有以下 ruby​​ 函数可以解决这个问题:

require 'sass'

module GETMODINT
def file_url(staticFilePath,staticHost,filePath)
assert_type filePath, :String
filePath = filePath.value #get string value of literal
staticFilePath = staticFilePath.value
staticHost = staticHost.value
modtime = File.mtime(filePath).to_i
#Sass::Script::Number.new(modtime)

fileBaseName = File.basename filePath, '.*'
fileDir = File.dirname(filePath).sub(staticFilePath,'')
fileExt = File.extname(filePath)
path = "url('#{staticHost}#{fileDir}/#{fileBaseName}.#{modtime}#{fileExt}')"
return Sass::Script::String.new(path)
end
Sass::Script::Functions.declare :modInt, [:filePath]
end

module Sass::Script::Functions
include GETMODINT
end

然后,在 sass mixin 中,我简单地引用 file_url 函数,将构建结果所需的参数传递给它:

@mixin backgroundImage($path, $position:0 0, $repeat:no-repeat) {
background: {
image:file_url($staticFilePath,$staticHost,$path);
position:$position;
repeat:$repeat;
}
}

在我的例子中,我用它来构建一个 css 背景图像路径。应该很容易修改以适应其他目的。

关于css - sass缓存破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9336575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com