No expires header sent, content cached, how long until browser makes conditional GET request?

心已入冬 提交于 2021-02-05 20:47:12

问题


Assume browser default settings, and content is sent without expires headers.

  1. user visits website, browser caches images etc.
  2. user does not close browser, or refresh page.
  3. user continues to surf site normally.
  4. 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.]


回答1:


HTTP/1.1 defines a selection of caching mechanisms; the expires header is merely one, there is also the cache-control header.

To directly answer your question: for a resource returned with no expires header, you must consider the returned cache-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 or expires 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.




回答2:


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.




回答3:


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).



来源:https://stackoverflow.com/questions/5860216/no-expires-header-sent-content-cached-how-long-until-browser-makes-conditional

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!