javascript - 从服务器加载已经存在的 HTML 文件而不是浏览器缓存

标签 javascript jquery html server browser-cache

我有一个实时网站,但由于变化总是存在,我需要用户查看最新的 HTML 文件,即从服务器而不是浏览器缓存加载文件。

当这个网站上线时,我不知道:

<meta http-equiv="Cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">

我在必要时使用 HTML、CSS、jQuery 和 PHP 制作了我的网站。

如何才能使网站直接从服务器加载?

最佳答案

I updated the HTML code with the meta tags, but since I already have the page in my cache, the new HTML code (with meta tags) is not running. I can simply hard refresh and work, but the users won't know or do that.

如果您需要强制每个人的浏览器重新加载纯 .html 页面,您可以添加 'Cache-Control` header您的网络服务器配置:

Nginx

location ~* \.(html)$ {
 add_header Cache-Control "no-cache, no-store";
}

Apache

<filesMatch ".(html)$">
    Header set Cache-Control "no-cache, no-store"
</filesMatch>

如果更改是在您的 .html 页面正在加载的文件中(例如 .js .css),您可以使用此“缓存清除”技术:

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.

这将强制浏览器加载新文件。

关于javascript - 从服务器加载已经存在的 HTML 文件而不是浏览器缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60147887/

相关文章:

javascript - 如何访问dust.js 中的 block 助手主体?

javascript - 下拉按钮未激活实现

javascript - jquery 捕获单词值

javascript - 从父窗口向子窗口发送参数

javascript - onkeyup 事件中未检测到文本区域更改?

javascript - Bootstrap 3 :navbar not working

javascript - 使用 JavaScript 或 jquery 更快?

javascript - 为什么这个 onMouseOut 事件在 Firefox 中没有触发?

javascript - 在线托管 node.js 项目

Javascript 从索引处的数组获取值,同时如果索引不存在则避免未定义?