Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default browser cache expiration period for text/html

Tags:

http

caching

In case there's no cache expiration related headers (except Date, Last-Modified and ETag) in an HTTP response what would be the expiration period for a resource if its Content-Type is text/html?

Does it depend on the browser?

like image 553
axk Avatar asked Dec 04 '10 18:12

axk


People also ask

How long before browser cache expires?

If a user stops using the browser it is indefinitely. If he/she uses the browser rarely, it will be until the expiration - either by internal policy or by HTTP headers. If he/she uses the browser heavily, it can be 12 minutes or even less.

How do you set Cache-Control max-age in HTML?

max-age. The max-age=N response directive indicates that the response remains fresh until N seconds after the response is generated. Indicates that caches can store this response and reuse it for subsequent requests while it's fresh.

What is the default value for cache policy?

The suggested default value is 32768.

Should HTML be cached?

Do not cache HTML in the browser. Always set cache-control: no-store, no-cache before sending HTML response to the client-side. Embed fingerprints in the URL of static resources like image, JS, CSS, and font files. Safely cache static resources, i.e., images, JS, CSS, font files for a longer duration like six months.


2 Answers

From the HTTP/1.1 specification on Response Cacheability:

If there is neither a cache validator nor an explicit expiration time associated with a response, we do not expect it to be cached, but certain caches MAY violate this expectation (for example, when little or no network connectivity is available).

That is the theory but I don’t have any information about actual behavior.

like image 166
Gumbo Avatar answered Oct 02 '22 16:10

Gumbo


I'm reasonably confident it's pretty much left up to the browser. They're trying to find the balancing point between "don't request the same HTML file every time unless we have to" and "don't miss updates if the webmaster was just incompetent". In the olden days space was also a concern, so users would play around with a little slider to set the cache usage - if you could set it all the way to 500MB you were a lucky man!

Nowadays pretty much everything is no-cache or Expires: -1 anyway (generated pages). But otherwise, I'm sure the old guidelines would apply.

I've always looked at the cache headers as an affirmative declaration - this response is good for however long, or it's only good once. But either way, it's defined. If it's left undefined, I wouldn't trust it to be purged.

like image 43
Robert Avatar answered Oct 02 '22 16:10

Robert