html - 更新样式表和缓存中引用的图像

标签 html css caching

如果从 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/

相关文章:

javascript - 网络音频 API : How to play a stream of MP3 chunks

html - 如何在导航栏中对齐图标

CSS div 第 n 个 child

java - 点燃缓存线程安全吗?

javascript - 样式建议下拉菜单

html - 如何在 HTML 中使用全局变量并在 typescript 中使用它?

javascript - HTML 表格的边距/填充/边框(?)问题

html - 没有JS的背景视频视差效果

javascript - jQuery 一直在我的 CDN 脚本中放置缓存破坏器?

python - Django 缓存导致数据库中出现重复键错误?