如何防止 x.jpg
从 css 文件被浏览器缓存?
这些图像必须每天刷新。
CSS 文件:
#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 文件中试过这个,但我不知道为什么它不起作用:
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>
最佳答案
[我的问题的答案]
我在我的图像目录中添加了这个 .htaccess 文件:
.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>
关于php - 如何防止 css 文件中的图像被缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22183258/