重新加载与刷新

发布于 2024-11-14 03:15:38 字数 410 浏览 4 评论 0原文

我有这个脚本

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断肠人 2024-11-21 03:15:38

我认为术语“刷新”和“重新加载”基本上是同义词。我在 RFC 2616 中看到这一行,它描述了 HTTP/1.1 缓存,它提供了可能的细微差别:

过期时间不能用于强制用户代理刷新其显示重新加载资源

换句话说,也许您可​​以说刷新是为了显示,而重新加载是为了资源。但由于浏览器对资源的主要用途是显示,因此我看不出有什么区别。

以下是一位处理浏览器缓存控制的开发人员对条款的简短文章 。他更喜欢的术语是:

  • 加载:在地址栏中按Enter;单击链接
  • 重新加载F5Ctrl+R;工具栏的刷新按钮;菜单->重新加载
  • 硬重新加载Ctrl+F5Ctrl+Shift+R

(硬重新加载会强制浏览器绕过其缓存。对于 Firefox,您可以按住 Shift kbd> 并按重新加载按钮。维基百科有 a列表介绍了如何针对常见浏览器执行此操作。您可以在此页面上测试其效果。 。)

为了回答有关 Firefox 如何决定何时刷新的问题,以下是 上面的链接解释了这一点:

  • 加载:在缓存资源过期之前不会发生请求
  • 重新加载:请求包含If-Modified-SinceCache-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:

An expiration time cannot be used to force a user agent to refresh its display or reload a resource

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:

  • load: hit Enter in the address bar; click on links
  • reload: F5; Ctrl+R; toolbar's refresh button; Menu -> Reload
  • hard reload: Ctrl+F5; Ctrl+Shift+R

(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:

  • load: no request happens until the cached resource expires
  • reload: the request contains the If-Modified-Since and Cache-Control: max-age=0 headers that allow the server to respond with 304 Not Modified if applicable
  • hard reload: the request contains the Pragma: no-cache and Cache-Control: no-cache headers and will bypass the cache
甜味拾荒者 2024-11-21 03:15:38

当人们刷新页面时,他们通常希望看到新的结果,因此缓存整个页面没有多大意义。

When people refresh a page, they generally expect to see new results, so caching of the entire page doesn't make much sense.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文