Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 989
Michael McCracken Avatar asked May 02 '11 17:05

Michael McCracken


People also ask

What sets how long a page will be cached on a browser before it expires?

The Expires property sets how long (in minutes) a page will be cached on a browser before it expires. If a user returns to the same page before it expires, the cached version is displayed.

How long does browser cache last?

The response can be cached by browsers and intermediary caches for up to 1 day (60 seconds x 60 minutes x 24 hours). The response can be cached by the browser (but not intermediary caches) for up to 10 minutes (60 seconds x 10 minutes). The response can be stored by any cache for 1 year.

How does no-cache header work?

The no-cache directive means that a browser may cache a response, but must first submit a validation request to an origin server.

Does browser cache GET request?

The basic idea behind it is the following: The browser requests some content from the web server. If the content is not in the browser cache then it is retrieved directly from the web server. If the content was previously cached, the browser bypasses the server and loads the content directly from its cache.


2 Answers

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.

like image 67
Peter Hart Avatar answered Sep 28 '22 09:09

Peter Hart


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.

like image 37
Jon Cram Avatar answered Sep 28 '22 08:09

Jon Cram