Browser caches are divided into strong cache and negotiated cache. When a client requests a resource, the process for obtaining the cache is as followsCopy the code
- Let’s start with some of this resource
http header
Determine whether it matches the strong cache. If it matches, the cache resources are directly obtained from the local server without sending requests to the server. - When the strong cache does not hit, the client sends a request to the server, and the server sends a request through another
request header
Verify that the resource matches the negotiated cache, calledhttp
Then verify that, if a match is hit, the server will request back, but does not return the resource, but tells the client to directly get the resource from the cache, the client will get the resource from the cache after receiving the return; - Strong and negotiated caches have in common that the server does not return the resource if the cache is hit; The difference is that strong caching does not send requests to the server, but negotiated caching does;
- When the negotiation cache also dies, the server sends the resource back to the client;
- when
ctrl+f5
When the page is forced to refresh, it is loaded directly from the server, skipping the strong cache and negotiated cache. - when
f5
When the page is refreshed, the strong cache is skipped, but the negotiated cache is checked.
Strong cache
Expires
(This field ishttp1.0
The value is an absolute time GMT-formatted time string representing the expiration time of the cache resource.Cache-Control:max-age
(This field ishttp1.1
The specification for strong caching utilizes itmax-age
Value to determine the maximum lifetime of the cache resource in seconds.
Negotiate the cache
Last-Modified
The value is the last update time of the resource, with the serverresponse
Return, even if the file is changed back, the date will change)If-Modified-Since
(Compare the two times to determine whether the resource was modified between requests. If not, the negotiated cache is hit.)ETag
A unique identifier that represents the content of the resource, along with the serverresponse
Return, only based on whether the contents of the file have changed)If-None-Match
The server compares the header of the requestIf-None-Match
With the current resourceETag
Consistency determines whether the resource has been modified between requests. If not, the negotiated cache is hit.)