重新加载与刷新
我有这个脚本
<?php
header("Expires: Sat, 11 Jun 2011 00:00:00 GMT");
echo "Hello World";
?>
,它只写“Hello World”并将缓存设置为下周六过期。
现在,当我在 FireFox 中加载此页面并单击重新加载按钮时,它会向服务器发出一个新请求来加载该页面,而不仅仅是从缓存中提供它(我认为要确保 last-modified
是否为仍然有效)。
但是,如果我将光标放在地址栏上并按 Enter,FireFox 将从缓存中提供内容。
为什么会这样呢?为什么在第一种情况下(重新加载)它向服务器发出请求,但在第二种情况下(刷新,我猜?)它从缓存提供服务?
I have this script
<?php
header("Expires: Sat, 11 Jun 2011 00:00:00 GMT");
echo "Hello World";
?>
It just writes "Hello World" and set the cache to expire on next Saturday.
Now, when I load this page in FireFox and click on reload button, it makes a new request to server to load the page instead of just serving it from cache (I think to ensure if last-modified
is still valid).
However, if I put my cursor on the address bar and press Enter, FireFox serves the contents from cache.
Why is that so? Why does in first case (reload) it makes a request to server, but in second case (refresh, I guess?) it serves from cache?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为术语“刷新”和“重新加载”基本上是同义词。我在 RFC 2616 中看到这一行,它描述了 HTTP/1.1 缓存,它提供了可能的细微差别:
换句话说,也许您可以说刷新是为了显示,而重新加载是为了资源。但由于浏览器对资源的主要用途是显示,因此我看不出有什么区别。
以下是一位处理浏览器缓存控制的开发人员对条款的简短文章 。他更喜欢的术语是:
(硬重新加载会强制浏览器绕过其缓存。对于 Firefox,您可以按住 Shift kbd> 并按重新加载按钮。维基百科有 a列表介绍了如何针对常见浏览器执行此操作。您可以在此页面上测试其效果。 。)
为了回答有关 Firefox 如何决定何时刷新的问题,以下是 上面的链接解释了这一点:
If-Modified-Since
和Cache-Control: max-age=0
标头,允许服务器在适用的情况下以304 Not Modified
进行响应Pragma: no-缓存
和缓存控制: no-cache
标头并将绕过缓存I think the terms 'refresh' and 'reload' are basically synonymous. I see this line in RFC 2616 that describes HTTP/1.1 caching that provides a possible slight difference:
In other words, perhaps you could say refreshing is for displays, and reloading is for resources. But since browsers' primary use for resources is display, I don't see a difference.
Here's a short writeup on the terms by a developer who has dealt with browser cache control. The terms he prefers are these:
(The hard reload forces the browser to bypass its cache. For Firefox, you hold down Shift and press the reload button. Wikipedia has a list of how to do this for common browsers. You can test its effect on this page.)
To answer your question about how Firefox decides when to refresh, here is how the link from above explains it:
If-Modified-Since
andCache-Control: max-age=0
headers that allow the server to respond with304 Not Modified
if applicablePragma: no-cache
andCache-Control: no-cache
headers and will bypass the cache当人们刷新页面时,他们通常希望看到新的结果,因此缓存整个页面没有多大意义。
When people refresh a page, they generally expect to see new results, so caching of the entire page doesn't make much sense.