【问题标题】:How to force a browser to clear the cache on my website .html files如何强制浏览器清除我网站 .html 文件上的缓存
【发布时间】:2023-03-11 00:31:02
【问题描述】:

我最近对客户网站进行了更改,但浏览器显示的是缓存版本。这是一个带有 .html 文件的静态网站。如果我删除浏览器上的缓存,它可以工作,但我真正想要的是强制每个访问者浏览器显示最新版本,而不必手动删除缓存。

我知道您可以在 .css 和 .js 文件上设置一个版本来显示最新版本,但是您如何使用静态 .html 文件来做到这一点?

【问题讨论】:

    标签: html caching browser


    【解决方案1】:

    如果这是关于.css.js 的更改,一种方法是“缓存破坏”是通过在每个版本的文件名中附加"_versionNo" 之类的内容。例如:

    script_1.0.css // This is the URL for release 1.0
    script_1.1.css // This is the URL for release 1.1
    script_1.2.css // etc.
    

    或者在文件名之后做:

    script.css?v=1.0 // This is the URL for release 1.0
    script.css?v=1.1 // This is the URL for release 1.1
    script.css?v=1.2 // etc.
    

    你也可以看看这里META TAGS

    【讨论】:

    • 嗨,这与 css 或 js 更改无关。这与 .html 页面上的内容有关
    • @Shaun 检查可能对您有帮助的链接
    【解决方案2】:

    我觉得最好不要缓存html文件

    <ifModule mod_headers.c>
    <FilesMatch "\.(html|htm|txt)$">
      Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
    </FilesMatch>
    </ifModule>
    

    保存。

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2016-02-18
      • 2015-02-18
      • 2016-10-01
      • 2019-01-02
      相关资源
      最近更新 更多