如果从 css 引用并缓存在用户设备上,我的图像会更新吗?
我有旧网站,我想确保所有用户都能获得新图像。
我已经更新了我的 css 链接以使用额外的查询字符串,这将强制更新样式表。
<link rel="stylesheet" type="text/css" href="~/site.css" />
这将确保我的样式会在用户访问页面后更新。 问题是关于引用图像
.header {
background-image: url(../logo.gif);
}
问题是我需要保持我的图像相同,因为它在整个页面和其他页面中都被引用。
我是否也需要将查询字符串放入 css 图片链接中,如下所示
.header {
background-image: url(../logo.gif?v=1);
}
我的理解是我需要使用方案二,
图片,因为它将被解析为 http://www.example.com/logo.gif因此它将针对浏览器进行检查,即:我需要将查询字符串添加到 css 中。
最佳答案
In modern web browsers it should work. Browser will check address of image and there is change (?v=whatever) - this url img.jpg?v=whatever is not cached so browser will load it again.
关于html - 更新样式表和缓存中引用的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33671333/