What happens if you don't set cache-control header?
If there is no Cache-Control
header and no Expires
header, but there is a Last-Modified
header (which most web servers send by default for static assets), most browsers will use heuristic freshness to determine how long to cache that asset for.
The typical calculation for this (which is the one suggested by RFC 7234) is:
(current time - last modified time) / 10
So, for example, if the last modified time for an image states it was last changed 60 days ago, a browser might decide it could reasonably use the locally cached version of that image for 6 days before checking for a new version.
Note that in most cases, if you hit refresh, you are telling the browser to fetch a fresh version, so in that situation this logic wouldn't apply.
Freshness as determined by actual browsers:
- Chrome still uses the old "10% of time since last_modified", matching the RFC's suggestion
- Same goes for Safari
-
Firefox nowadays uses
min(one week, (current time - last modified time) / 10)
. So freshness is never more than one week
Related videos on Youtube
Nishant
Updated on September 18, 2022Comments
-
Nishant over 1 year
What happens if you don't set the
cache-control
header? Does HTTP specify a default behaviour that clients should follow or is it up to the clients to decide?In Chrome, I have seen some Javascript requests that have no
cache-control
headers showing up as200 (from disk cache)
. Is Chrome optimizing this?In IE, I have seen it show up as a
304 (not modified)
.How do I understand this better?
-
Tim Fountain over 6 years"no cache headers" meaning no Cache-Control header, or really no cache headers? Cache-control is not the only header that affects caching. Most web servers will send Last Modified headers for static assets like Javascript files.
-
-
bertonc96 about 4 yearsAnd if there is no
Last-Modified
header? -
aross over 3 yearsThis is the answer I've been looking for. I am curious, however, what various browsers have as default.
-
aross over 3 years@bertonc96 It seems to be 0 in that case. See for example this.