Search code examples
cachingbrowsercache-control

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


Solution

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