为什么Google Chrome浏览器在定义HTTP“过期”时不使用缓存页面?头 [英] Why does Google Chrome NOT use cached pages when I define the HTTP "Expires" header

查看:282
本文介绍了为什么Google Chrome浏览器在定义HTTP“过期”时不使用缓存页面?头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过https:// [host]:{port} /(with []发送有效格式化的HTTP响应过期标题(例如Wed,04 May 2011 09:29:09 GMT使用 response.setDateHeader(Expires,{将来几秒钟内的毫秒数)),从J2EE应用程序中获取主机名。

在我的页面上,我有一个指向同一页面的链接。当我从Firefox(4)或IE(8)中单击此链接时,页面将从缓存中重新加载,直到达到过期时间。一旦过期时间通过,点击相同的链接会导致页面从服务器加载新数据。如果我在上述两种浏览器中都选择了F5,则页面会重新加载来自服务器的新数据(Firebug向我显示: Cache-Control:max-age = 0 正在与请求一起发送)。



使用谷歌浏览器,F5和点击链接都具有相同的效果。该页面总是通过新数据从服务器重新加载。

我无法找到任何有据可查的解释。



是否有人知道为什么在我的情况下,Google Chrome并不尊重服务器使用页面响应发送的过期标头,因此始终向服务器请求数据?

解决方案

Chrome在这方面的工作方式会造成极度的混淆。看起来按F5或重新加载此页面只是防止chrome从缓存中提供请求。这很容易与在url窗口中按enter键进行比较,即使在两种情况下,请求标头(不会发送到任何地方)都具有Cache-Control:max-age = 0。 >

如果按下ctrl + F5,您将得到Cache-Control:no-cache。我认为F5& ctrl + F5是这两个都会导致一个请求被发送到服务器,但在ctrl + F5的情况下,服务器应该知道不响应一个304没有修改。


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?

解决方案

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.

这篇关于为什么Google Chrome浏览器在定义HTTP“过期”时不使用缓存页面?头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆