gpt4 book ai didi

iis - Chrome 是否忽略缓存控制 : max-age?

转载 作者:行者123 更新时间:2023-12-01 23:20:24 26 4
gpt4 key购买 nike

背景:

  • IIS 7
  • AspNet 3.5 网络应用

Chrome 开发工具列出了 98 个针对 Web 应用程序主页的请求(aspx + js + css + 图像)。在以下请求中,css/images 文件的状态代码为 200。没有缓存信息,浏览器每次都会询问服务器是否需要更新文件。好的。

在 IIS 7 中,我设置了用于缓存控制的 HTTP header ,将“ressources”文件夹设置为 6 小时。在 Chrome 中,使用开发工具,我可以看到 header 在响应中设置得很好:

Cache-Control: max-age=21600

但我仍然收到 98 个请求...我认为如果未达到过期日期,浏览器不应该请求一项资源,并且我预计请求数量会下降...

最佳答案

我明白了。如果您在同一选项卡中向同一 URI 发出另一个请求后立即发出请求(通过单击刷新按钮,按F5 键或按 Command + R)。它可能有一个算法来猜测用户真正想做的事情。

测试 Cache-Control header 的一种方法是返回一个带有指向其自身的链接的 HTML 文档。单击链接时,Chrome 会从缓存中提供文档。例如,将以下文档命名为 self.html:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test Page</title>
</head>
<body>
<p>
<a href="self.html">Link to the same page.</a>
If correctly cached, a request should not be made
when clicking the link.
</p>
</body>
</html>

另一个选项是复制 URL 并将其粘贴到同一选项卡或另一个选项卡中。

更新:关于Chrome post published on January 26, 2017 ,它描述了之前的行为是什么,以及它是如何通过仅重新验证主资源而不是子资源来改变的:

Users typically reload either because a page is broken or the content seems stale. The existing reload behavior usually solves broken pages, but stale content is inefficiently addressed by a regular reload, especially on mobile. This feature was originally designed in times when broken pages were quite common, so it was reasonable to address both use cases at once. However, this original concern has now become far less relevant as the quality of web pages has increased. To improve the stale content use case, Chrome now has a simplified reload behavior to only validate the main resource and continue with a regular page load. This new behavior maximizes the reuse of cached resources and results in lower latency, power consumption, and data usage.

Facebook post also published on January 26, 2017中,据说他们发现了一个 piece of code Chrome 是否在 POST 请求后使所有缓存资源失效:

we found that Chrome would revalidate all resources on pages that were loaded from making a POST request. The Chrome team told us the rationale for this was that POST requests tend to be pages that make a change — like making a purchase or sending an email — and that the user would want to have the most up-to-date page.

现在看来情况不再是这样了。

最后,介绍了 Firefox 正在引入 Cache-Control: immutable 来完全停止资源的重新验证:

Firefox implemented a proposal from one of our engineers to add a new cache-control header for some resources in order to tell the browser that this resource should never be revalidated. The idea behind this header is that it's an extra promise from the developer to the browser that this resource will never change during its max-age lifetime. Firefox chose to implement this directive in the form of a cache-control: immutable header.

关于iis - Chrome 是否忽略缓存控制 : max-age?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11245767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com