远程清除IE缓存
我们最近推出了新的 CMS 解决方案。然而我们没有意识到,默认情况下该解决方案不会向 HTML 页面添加无缓存标头等。
虽然我们现在已经解决了这个问题,但使用 IE 的访问者尤其会缓存大部分 HTML 页面(包括对旧 CSS 和 JS 文件的引用)。
对于在上线后第一个月访问该网站的用户来说,是否有办法清除缓存?因为我担心由于人们使用旧的缓存版本,我们无法成功地推进我们的设计和 JS 功能。
We recently went live with a new a CMS solution. However we didn't realise that by default this solution does not add a no-cache header, etc. to HTML pages.
Whilst we have now fixed this, our visitors using IE especially have a cache of the bulk of our HTML pages (including references to old CSS and JS files).
Is there a way of cache busting for those users who visited the site in the first month post go-live? As I'm worried that we can't successfully move forward with our design and JS functionality because of people with an old cached version.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对页面的请求通常会返回
Last-Modified
标头吗?这是我所经历过的唯一可靠的破坏缓存的方法。大多数浏览器在缓存某些内容时都会发送
If-Unmodified-Since
请求标头(除非此 CMS 上的默认缓存行为是设置显式缓存到期日期,这是极其不寻常的)。因此,您所要做的就是在响应中发出Last-Modified:[date you added no-cache headers]
标头,并且行为正确的 HTTP 服务器将向客户端发送完整更新的 HTML页。正确的格式可以在HTTP协议中找到。
Do requests to the page normally return a
Last-Modified
header? That's the only reliable way to bust caches I have any experience with.Most browsers will send an
If-Unmodified-Since
request header if they're caching something (unless the default caching behavior on this CMS was to set an explicit cache expiry date, which would be extremely unusual). So, all you'd have to do is emit aLast-Modified:[date you added no-cache headers]
header in the response, and a correctly behaving HTTP server would send clients the full updated HTML page.Correct format can be found in the HTTP protocol.
假设有一个中央 URL 生成函数,跟踪它并始终附加
?_version=2
(或&_version=2
,如果 URL 中已存在问号)到所有 URL。这不会对您的 Web 应用程序产生任何影响(除非它使用 _version GET 字段),但会模拟所有链接资源的已更改 URL。由于始终会请求初始 URL(例如
/
),这将使任何浏览器重新下载所有资源。Assuming a central URL generation function, track it down and always append
?_version=2
(or&_version=2
, if there is a question mark in the URL already) to all URLs.This will have no effect on your web application (unless it uses the _version GET field), but simulate changed URLs all linked resources. Since the initial URL (say,
/
) will always be requested, this will make any browser redownload all resources.