部署后强制缓存刷新缓存

2023-09-02 00:21:45 作者:我的霸气你学不来

有没有办法强制客户端的缓存重新加载HTML文件,如果你不能改变的URI引用该文件(例如,不能添加时间戳参数)?

Is there a way to force a client's cache to reload an HTML file if you can't change the URI referencing that file (e.g., can't add a timestamp param)?

下面是我的情况:

部署到1000个用户一个插件 在该插件加载 example.com/page.html 上调用的script.js 在资源URI example.com/page.html 不能被改变(W / O插件更新) page.html即可 已被更改。我需要清除用户的高速缓存中的旧 page.html即可因此,新的 page.html即可可以加载。 A plugin deployed to a 1000 users That plugin loads example.com/page.html which calls on script.js The resource URI example.com/page.html cannot be changed (w/o plugin updates) page.html has been changed. I need to clear the old page.html from users' cache so the new page.html can load.

任何想法? htaccess的? PHP的API,老和放大器;新 page.html即可呼吁?

Any ideas? Htaccess? The PHP API that the old & new page.html call on?

谢谢!

推荐答案

那么,如果页面已经被缓存由浏览器很难告诉它不要使用其缓存的版本,因为它可能不会刻意去之前再次检查这决定了它的缓存的版本是陈旧的。你只需要发送一个蜗牛邮件写信给所有用户,通知他们到preSS Ctrl + F5:)

Well, if the page is already cached by a browser it's difficult to tell it not to use its cached version because it probably won't bother to check again before it determines its cached version is stale. You'll just have to send a snail-mail letter to all of your users informing them to press ctrl+f5 :)

有机会的话,浏览器可能会至少尝试HEAD请求,检查修改后的时间戳之前它服务了它的缓存的版本,虽然。在这种情况下,下面会帮助你。

There is a chance that the browser might at least try a HEAD request to check the modified timestamp before it serves up its cached version, though. In this case the following will help you out.

浏览器使用的HTTP标头从Web服务器协商的内容。展望未来,如果你想告诉浏览器不缓存文件,你必须适当的HTTP标头中发送。如果你想这样做,在PHP中您可以使用函数相应的HTTP标头中发送到浏览器:

Browsers negotiate their content from your web server using HTTP standard headers. Going forward if you want to tell a browser not to cache a file, you have to send the appropriate HTTP headers. If you want to do this in PHP you can use the header function to send the appropriate HTTP headers to the browser:

header('Cache-Control: no-cache');
header('Pragma: no-cache');

如果它必须通过HTML做,你可以做你的网页标题中的下列内容:

If it has to be done via HTML you can do the following in your page header:

<meta http-equiv="Expires" content="Tue, 01 Jan 1995 12:12:12 GMT">
<meta http-equiv="Pragma" content="no-cache">

有没有方法可以让你以确保浏览器是否会兑现但是你的要求,它不缓存的网页。还有一些其他的东西像ETag的和诸如此类的东西,但坦白说,我不认为这会帮助你,如果页面已经被缓存。

There is no way for you to be sure if the browser will honor your request that it not cache a page, however. There are some other things like eTags and whatnot but frankly I don't think that's going to help you out if the page is already cached.

更新

从HTTP / 1.1规范的响应可缓存:

From the HTTP/1.1 specification on Response Cacheability:

如果既没有缓存验证,也没有一个明确的到期时间   与反应有关,我们不希望它被缓存,但   某些缓存可能,当小违反这种预期(例如   或者没有网络连接不可用)。

If there is neither a cache validator nor an explicit expiration time associated with a response, we do not expect it to be cached, but certain caches MAY violate this expectation (for example, when little or no network connectivity is available).