I just checked the cache-control header returned by webmasters.stackexchange.com. The only directive present in the response is cache-control: private
. In this case, what are the default values for other directives including max-age? Should a client re-validate (checking if the content is modified on the server) for every request?
1 Answer
Mozilla has a HTTP Caching FAQ that says:
[In this case] then the expiration calculation is essentially the algorithm described in RFC 2616 section 13.2.
...
The expiration time is computed as follows:
expirationTime = responseTime + freshnessLifetime - currentAge
where
responseTime
is the time at which the response was received according to the browser....
The freshness lifetime is calculated based on several headers. ... If [neither
max-age
norExpires
header are] present, then we look for aLast-Modified
header. If this header is present, then the cache's freshness lifetime is equal to the value of theDate
header minus the value of theLast-modified
header divided by 10.
When I investigated this heuristic of Last-modified / 10
for Why is this response being cached?, I found that all major browsers appear to use this same heuristic.
According to Cache-Control - HTTP | MDN, clients must only revalidate if one of the following headers is present:
no-cache
max-age=0, must-revalidate
Since neither of those headers are present in this case, no revalidation needs to occur.
-
Sorry if I am missing something. But what if last-modified header isn't present? I couldn't find one in the response of webmasters.stackexchange.com. In such cases, do browsers use some default value?– KannanJun 1, 2021 at 11:11
-
1Most pages on this site have
Last-modified
:curl --head https://webmasters.stackexchange.com/questions/134583/default-cache-control-directives-and-behaviour-when-header-returns-only-privat/134589
showslast-modified: Tue, 01 Jun 2021 11:11:17 GMT
. It appears that the home page does not and I'm not sure what browsers assume in that case. I'd assume they have to use "modified just now" as the default because there is no other sane assumption. Jun 1, 2021 at 11:31