35

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

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Michael McCracken
  • 391
  • 1
  • 3
  • 6
  • A good practical answer is here: http://webmasters.stackexchange.com/questions/53942/why-is-this-response-being-cached – Tim Grant Oct 18 '16 at 15:12
  • Also here https://webmasters.stackexchange.com/questions/111298/what-happens-if-you-dont-set-cache-control-header – cachius Feb 09 '22 at 12:51

3 Answers3

29

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.

Peter Hart
  • 4,955
  • 2
  • 25
  • 30
10

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.

Jon Cram
  • 16,609
  • 24
  • 76
  • 107
  • 2
    It appears that when the browser cache is full, it starts using it's cache eviction algorithm. Until then - only a refresh command or the end of that browser session will cause it to request those representations again. – Michael McCracken May 03 '11 at 00:43
  • 29
    The third paragraph is actually incorrect. From the referenced specification on caching (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. – Peter Hart Mar 18 '14 at 21:06
  • @PeterHart will vote up if you put that as an answer – Phil Jan 25 '17 at 10:33
4

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

lukiffer
  • 11,025
  • 8
  • 46
  • 70
  • Thanks for the answer lukiffer, but I was asking specifically about the scenario where the user doesn't refresh the page (item #2 above). – Michael McCracken May 02 '11 at 17:43
  • If the user doesn't close or refresh the page, there is no need for the HTTP client to ever re-request a resource on that page. – Jon Cram May 02 '11 at 17:48
  • Hey Jon, using point #3 - if the user continues to surf the site normally, images/css/js may need to be used. From what I'm seeing - the browser dumps the cache *generally* on a session basis, but doesn't do conditional get requests unless the user hits refresh (even when browsing to a new page which already cached images are found) – Michael McCracken May 02 '11 at 20:55
  • @Michael: that's interesting to know, it'd be great if you could write up what you find some day! – Jon Cram May 03 '11 at 18:42