为什么当我定义 HTTP“过期”时 Google Chrome 不使用缓存页面标头
我正在发送格式有效的 HTTP 响应“过期”标头(例如“Wed,2011 年 5 月 4 日 09:29:09 GMT”),其中页面通过 https://[host]:{port}/ 提供([host] 为localhost),使用response.setDateHeader("Expires", {未来几秒的毫秒数})。
在我的页面上,我有一个指向同一页面的链接。当我在 Firefox (4) 或 IE (8) 中单击此链接时,页面将从缓存中重新加载,直到达到过期时间。一旦过了过期时间,单击同一链接就会导致从服务器加载包含新数据的页面。如果我在上述任一浏览器上按 F5,页面就会重新加载来自服务器的新数据(Firebug 显示 Cache-Control: max-age=0
正在与请求一起发送)。
对于 Google Chrome,F5 和单击链接具有相同的效果。该页面始终从服务器重新加载新数据。
我无法找到关于这种效应的任何有据可查的解释。
有谁知道为什么在我的情况下 Google Chrome 不尊重服务器随页面响应发送的“过期”标头,因此总是从服务器请求数据?
I am sending validly formatted HTTP response "Expired" headers (e.g. "Wed, 04 May 2011 09:29:09 GMT") with a page served through https://[host]:{port}/ (with [host] being localhost) from a J2EE application, using response.setDateHeader("Expires", {milliseconds a few seconds in the future} )
.
On my pages I have a link to the same page. When I click this link from within Firefox (4) or IE (8), the page is reloaded from cache until the Expired time is reached. Once the Expired time is passed, clicking on the same link results in the page being loaded from the server with fresh data. If I hit F5 on either of the mentioned browsers, the page is reloaded with new data from the server (Firebug shows me that Cache-Control: max-age=0
is being sent with the request).
With Google Chrome, both F5 and clicking on the link have the same effect. The page is ALWAYS reloaded from the server with new data.
I was unable to find any well documented explanation of this effect.
Does any one know why in my case Google Chrome is not respecting the "Expired" headers the server is sending with the page responses and thus ALWAYS requesting the data from the server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Chrome 在这方面的工作方式可能会引起极大的混乱。似乎按 F5 或“重新加载此页面”只是阻止 Chrome 处理来自缓存的请求。这很容易与在 url 窗口中按 Enter 键进行比较,在 url 窗口中它将使用缓存,即使在这两种情况下请求标头(不会发送到任何地方)都有 Cache-Control: max-age=0。
如果按 ctrl+F5,您将得到 Cache-Control: no-cache。我认为F5和F5之间的区别ctrl+F5 的优点是两者都会导致请求发送到服务器,但在 ctrl+F5 的情况下,服务器应该知道不会响应 304 未修改。
The way chrome works in this respect can cause extreme confusion. It seems that pressing F5 or "reload this page" simply prevents chrome from serving a request from the cache. This is easily compared with pressing enter in the url window, where it will use the cache, even though in both cases the request header (which doesn't get sent anywhere) has Cache-Control: max-age=0.
If you press ctrl+F5 you get Cache-Control: no-cache. I think the difference between F5 & ctrl+F5 is that both will result in a request being sent to the server, but in the ctrl+F5 case the server should know to not respond with a 304 not modified.