强制浏览器重新读取缓存的图像 [英] Force browser to re-read cached images
问题描述
.button {
background:url(../ Images / button.png);
}
问题:出于性能原因,所有静态内容都有过期标头,并由浏览器缓存。当图像更改时,用户必须刷新缓存(IE中的Ctrl + F5)。
问题:是下一个方法是否有效? .button {
background:url(../ Images / button.png?v = 1234);
}
其中v = 1234是我的网站的版本。我不知道是否是100%有效的在CSS中写这样的事情,我想要浏览器仍然缓存图像,如果版本是一样的。所有现代浏览器是否正确地使用网址参数部分缓存数据?
谢谢。
这对我来说是一个很好的方法,它在现代浏览器的CSS工作正常 - 浏览器将查看图像的地址(包括?v = 1234
),看到它没有缓存,并发送一个新的请求。
.button { background: url(../Images/button.png); }
Problem: for performance reason all static content has expiration headers and is cached by browser. When image changes user must refresh cache (Ctrl+F5 in IE). I want images to be cached, but when necessary they must be automatically reloaded.
Question: is next approach 'valid'?
.button {
background: url(../Images/button.png?v=1234);
}
where v=1234 is version of my site. I do not know whether it is 100% valid to write such things in CSS and I do want browsers to still cache images if version is the same. Do all modern browsers correctly cache data with URL parameters part?
Thanks.
That looks like a good approach to me, it'll work fine in CSS in modern browsers - the browser will look at the address of the image (including the ?v=1234
), see that it's not cached, and send a fresh request.
这篇关于强制浏览器重新读取缓存的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!