没有发送过期标头,缓存内容,浏览器发出条件 GET 请求需要多长时间?
假设浏览器默认设置,并且发送的内容没有过期标头。
- 用户访问网站,浏览器缓存图像等。
- 用户不会关闭浏览器或刷新页面。
- 用户继续正常浏览网站。
- 假设浏览器不会出于任何原因转储缓存。
当用户浏览时,浏览器会缓存图像等,但尚不清楚何时会发出条件 GET 请求来询问内容新鲜度(除了刷新页面)。如果这是特定于浏览器的设置,我在哪里可以看到它的值(对于以下浏览器:safari、IE、FireFox、Chrome)。
[编辑:是的 - 我知道你应该始终发送过期标头。然而,这项研究的目的是了解浏览器如何处理没有过期标头的内容。]
Assume browser default settings, and content is sent without expires headers.
- user visits website, browser caches images etc.
- user does not close browser, or refresh page.
- user continues to surf site normally.
- assume the browse doesn't dump the cache for any reason.
The browser will cache images etc as the user surfs, but it's unclear when it will issue a conditional GET request to ask about content freshness (apart from refreshing the page). If this is a browser specific setting, where can I see it's value (for browsers like: safari, IE, FireFox, Chrome).
[edit: yes - I understand that you should always send expires headers. However, this research is aimed at understanding how the browser works with content w/o expires headers.]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 HTTP 缓存规范(第 13.4 节):除非特别约束缓存控制(第 14.9 节)指令,缓存系统可以始终将成功的响应(参见第 13.8 节)存储为缓存条目,可以如果是新鲜的,则无需验证即可返回,并且可以在验证成功后返回。这意味着如果没有发送缓存控制标头,用户代理可以自由地执行任何操作。大多数浏览器结合使用用户设置和启发式方法来确定在这种情况下是否缓存(以及缓存多长时间)。
From the the HTTP caching spec (section 13.4): Unless specifically constrained by a cache-control (section 14.9) directive, a caching system MAY always store a successful response (see section 13.8) as a cache entry, MAY return it without validation if it is fresh, and MAY return it after successful validation. This means that a user agent is free to do whatever it wants if no cache control header is sent. Most browsers use a combination of user settings and heuristics to determine whether (and how long) to cache in this situation.
HTTP/1.1 定义了一系列缓存机制;
expires
标头只是其中之一,还有cache-control
标头。要直接回答您的问题:对于返回没有
expires
标头的资源,您必须考虑返回的cache-control
指令。HTTP/1.1 没有为没有缓存相关标头的资源定义缓存行为。如果发送的资源没有
cache-control
或expires
标头,您必须假设客户端在下次请求相同资源时将发出常规(无条件)请求。任何偏离此行为的客户端都将被视为不完全符合要求的 HTTP 客户端,在这种情况下,问题就变成:不符合要求的 HTTP 客户端会出现什么行为?没有办法回答这个问题。
HTTP 缓存很复杂,要完全理解一致的客户端在给定场景中应该做什么,请阅读并理解 HTTP 缓存规范。
HTTP/1.1 defines a selection of caching mechanisms; the
expires
header is merely one, there is also thecache-control
header.To directly answer your question: for a resource returned with no
expires
header, you must consider the returnedcache-control
directives.HTTP/1.1 defines no caching behaviour for a resource served with no cache-related headers. If a resource is sent with no
cache-control
orexpires
headers you must assume the client will make a regular (non-conditional) request the next time the same resources is requested.Any deviation from this behaviour qualifies the client as being not a fully conformant HTTP client, in which case the question becomes: what behaviour is to be expected from a non-conformant HTTP client? There is no way to answer that.
HTTP caching is complex, to fully understand what a conformant client should do in a given scenario, read and understand the HTTP caching spec.
除非您发送过期标头,否则大多数浏览器将为每次后续刷新发出 GET 请求,并且将获得 HTTP 200 OK(它将再次下载内容)或 HTTP 304 Not Modified(并使用缓存中的数据)。
Unless you send an expires header, most browsers will make a GET request for each subsequent refresh and will either get HTTP 200 OK (it will download the content again) or HTTP 304 Not Modified (and use the data in cache).