我试图让所有样式表看起来像:
<link href="style.css?v=1234" rel="stylesheet" type="text/css" />
我遇到的唯一问题是获取当前链接标签,然后将新的随机数应用于当前路径。我认为我应用查找链接的方法还可以,但是获取当前属性然后应用新属性是我出错的地方。
$(document).ready(function() {
var randomNum = Math.ceil(Math.random()*2);
// is this the best way?
$("head").find("link").attr("href")+"?v="+randomNum;
// I don't think this works
$('link[rel="stylesheet"]').end()+"?v="+randomNum;
});
我有一群人遇到缓存问题,他们指出这将是一个可能的解决方案。