Why does checking "Disable cache" in Developer Tools cause Cache-Control: no-cache
to be sent in the request?
no-cache
means check with the server to see if the cached copy is the same as what's on the server, if it is, use that, if not, then get the new version.
But, if the cache is disabled, then the client has to request a new version from the server regardless.
So why does it bother sending no-cache
?
Also, isn't no-cache
pointless without also sending If-None-Match
? Otherwise the server has no way of knowing what version of the file is in your cache.
I guess there is no cached version so it can't send the ETag
in the If-None-Match
, which brings me back to the original question of why no-cache
is used at all.
After clearing the cache, unchecking the "Disable cache" checkbox, and refreshing the page, you can see no Cache-Control
header is sent:
CodePudding user response:
no-cache
means check with the server to see if the cached copy is the same as what's on the server, if it is, use that, if not, then get the new version.
no-cache
means: "a cache MUST NOT use a stored response to satisfy the request without successful validation on the origin server." It doesn't require a conditional request, a regular GET
would also satisfy that definition.
So why does it bother sending
no-cache
?
To prevent intermediate caches from returning a cached version without validation.
Also, isn't
no-cache
pointless without also sendingIf-None-Match
? Otherwise the server has no way of knowing what version of the file is in your cache.
The browser is not making a conditional request (though it could), so it doesn't use If-None-Match
. An intermediate cache, though, could have a cached version with an ETag
, which it could revalidate. Or not.
I think the point you're missing is that this directive is directed at intermediate caches, to control their behavior.