gpt4 book ai didi

http - 为什么浏览器不遵守 Cache-Control header ?

转载 作者:可可西里 更新时间:2023-11-01 16:31:55 24 4
gpt4 key购买 nike

我在 S3 上有一张图片,它的 Cache-Control header 设置为 public, max-age=3600。因此,下游系统(代理、浏览器等)应将其缓存 1 小时。

我可以看到浏览器在后续请求后返回 304(未修改)。

然后我就去 更新 S3 上的那个图像(资源没有版本化..URL 没有改变,只是 _content),但是浏览器去获取了 < em>新版本。 (例如 HTTP 200)。

这是 chrome 网络流量:

enter image description here

要求:

  1. 200(好)
  2. 304(未修改)

~图片在幕后改变了~

  1. 200(好)
  2. 304(未修改)

这是响应头: enter image description here

这怎么可能?我没有设置正确的标题吗?

有两件事让我感到困惑:

  1. 响应仍应为 304(未修改)?浏览器如何知道去获取图像? max-age 尚未达到?
  2. chrome 不应该显示“来自磁盘缓存”之类的吗? (实际上不是到服务器?)

我的猜测是 - 我没有设置正确的缓存控制 header 或其他内容。那么有人可以阐明这种行为,让我知道我需要做什么才能将资源缓存 1 小时 :)

谢谢!

最佳答案

响应中指定了ETag

ETag 在规范中是这样解释的

An entity-tag can be more reliable for validation than a modificationdate in situations where it is inconvenient to store modification
dates, where the one-second resolution of HTTP date values is not
sufficient, or where modification dates are not consistently
maintained.

因此浏览器更喜欢它而不是基于日期的过期时间。

因此,您的浏览器每次都会发出请求,除非内容已更改 - 否则会返回 http 304。否则 - 它是 http 200。

如果您只想要基于时间的过期 - 删除 ETag

引用资料:

关于http - 为什么浏览器不遵守 Cache-Control header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51256951/

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