我有一个实时网站,但由于变化总是存在,我需要用户查看最新的 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/