HTTP 缓存控制 max-age,必须重新验证

发布于 2024-09-03 12:57:25 字数 368 浏览 2 评论 0原文

我有几个与缓存控制相关的疑问。

如果我为静态 html/js/images/css 文件指定 Cache-Control max-age=3600, Must-revalidate ,并在 HTTP 标头中定义 Last Modified 标头:

  1. 浏览器/代理是否缓存(例如Squid/Akamai)是否在 max-age 过期之前一直到源服务器进行验证?或者它会从缓存中提供内容直到 max-age 过期吗?
  2. max-age 过期(即缓存过期)后,是否存在 If-Modified-Since 检查,或者是否从源服务器重新下载内容而不进行 If-Modified-Since 检查?

I have a couple of queries related to Cache-Control.

If I specify Cache-Control max-age=3600, must-revalidate for a static html/js/images/css file, with Last Modified Header defined in HTTP header:

  1. Does browser/proxy cache(like Squid/Akamai) go all the way to origin server to validate before max-age expires? Or will it serve content from cache till max-age expires?
  2. After max-age expiry (that is expiry from cache), is there a If-Modified-Since check or is content re-downloaded from origin server w/o If-Modified-Since check?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

少女七分熟 2024-09-10 12:57:25

a) 如果服务器包含此标头:

Cache-Control "max-age=3600, must-revalidate"

它告诉客户端缓存和代理缓存,一旦内容过时(超过 3600 秒),它们必须在源服务器上重新验证,然后才能提供内容。这应该是缓存系统的默认行为,但是 must-revalidate 指令使这一要求变得明确。

b) 客户应重新验证。它可能会使用带有 ETag 的 If-MatchIf-None-Match 标头重新验证,也可能使用 If-Modified-Since或带有日期的 If-Unmodified-Since 标头。

a) If the server includes this header:

Cache-Control "max-age=3600, must-revalidate"

it is telling both client caches and proxy caches that once the content is stale (older than 3600 seconds) they must revalidate at the origin server before they can serve the content. This should be the default behavior of caching systems, but the must-revalidate directive makes this requirement unambiguous.

b) The client should revalidate. It might revalidate using the If-Match or If-None-Match headers with an ETag, or it might use the If-Modified-Since or If-Unmodified-Since headers with a date.

时间海 2024-09-10 12:57:25

一个。查看 此页面,看看会发生什么。

b.过期后,浏览器将在服务器上检查文件是否已更新。如果没有,服务器将使用 304 Not Modified 标头进行响应,并且不会下载任何内容。

您可以通过查看 Firebug 或类似工具中的“网络”面板自行检查此行为。只需在地址栏中重新输入 URL,然后将 HTTP 请求数与缓存为空时的请求数进行比较即可。

a. Look at the ‘Stats’ tab on this page and see what happens.

b. After expiration the browser will check at the server if the file is updated. If not, the server will respond with a 304 Not Modified header and nothing is downloaded.

You can check this behaviour yourself by looking at the ‘Net’ panel in Firebug or similar tools. Just re-enter the URL in the address bar and compare the number of HTTP requests with the number of requests when your cache is empty.

吻风 2024-09-10 12:57:25

给出的答案是不正确的,至少对于 2019 年的网络浏览器来说是

这样。“过期后,浏览器将在服务器上检查文件是否已更新”<- 不正确

我有一个静态文件,其中包含“Cache-Control: public,must” -revalidate,max-age=864000" 并且 Chrome 和 Firefox 每次都会发出请求(并且每次都会收到 304 Not Modified)。

The given answers are incorrect, at least for web browsers in 2019.

"After expiration the browser will check at the server if the file is updated" <- not true

I have a static file served with "Cache-Control: public,must-revalidate,max-age=864000" and both Chrome and Firefox do a request every time (and get a 304 Not Modified back every time).

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