如何防止浏览器缓存css文件中的x.jpg
?
这些图像必须每天刷新。
#slider{
background: url(1.jpg) 0 0 no-repeat,
url(2.jpg) 313px 0 no-repeat,
url(3.jpg) 626px 0 no-repeat,
url(4.jpg) 939px 0 no-repeat,
url(5.jpg) 1252px 0 no-repeat,
url(6.jpg) 1565px 0 no-repeat,
url(7.jpg) 1878px 0 no-repeat,
url(8.jpg) 2191px 0 no-repeat;
}
我在我的php文件中尝试了这个,但我不知道它为什么不起作用:
<script>
$("#slider").css(
"background",
"url(1.jpg?v=<?php echo time(); ?>) 0 0 no-repeat," +
"url(2.jpg?v=<?php echo time(); ?>) 313px 0 no-repeat," +
"url(3.jpg?v=<?php echo time(); ?>) 626px 0 no-repeat," +
"url(4.jpg?v=<?php echo time(); ?>) 939px 0 no-repeat," +
"url(5.jpg?v=<?php echo time(); ?>) 1252px 0 no-repeat," +
"url(6.jpg?v=<?php echo time(); ?>) 1565px 0 no-repeat," +
"url(7.jpg?v=<?php echo time(); ?>) 1878px 0 no-repeat," +
"url(8.jpg?v=<?php echo time(); ?>) 2191px 0 no-repeat"
);
</script>
答案 0 :(得分:0)
[我的问题的答案]
我在我的图像目录中添加了这个.htaccess文件:
<filesMatch "\.(jpg)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>