Browser Cache policy
- The browser cache is divided into
Strong cache
andNegotiate the cache
They are all passedHTTP packet cache identifier
Strong cache
- The cache identifiers for strong caching are
Expires
,Cache-Control
- Expires is
HTTP / 1.0
If the client’s time is less than Expires, use the cachehttp1.1
Expires has been replaced by the cache-control field.Cache-Control
Are fields for precise control of the cache. It has the following values - Public: All content will be cached (both client and proxy can be cached)
Private: All content can be cached only by the client. The default value of cache-control
No-cache: indicates the contents of the client cache, but whether to use the cache is verified by the negotiated cache
No-store: All content is not cached, that is, neither mandatory cache nor negotiated cache is used
Max-age = XXX (XXX is numeric) : The cache contents will expire after XXX seconds
Negotiated cache (weak cache)
- If the cache flag does not hit the strong cache, the negotiation cache is passed. The negotiated cache is also determined by the cache identifier if it is cached
Etag/ If-None-Match
:Etag
isServer request response
Is returnedUnique identification of the current resource
. When the client sends the request,If-None-Match
Will carry onThe last time
The returnedEtag
, the server will compare the if-none-match field to the Etag of the resource in the server.If the same
, indicating that the resource is not updated304
. If they are inconsistent, the resource file is returned with the status code 200Last-Modified/ If-Modified-Since
:Last-Modified
isThe server returns the last time the resource was modified
. Returned by the server to the client.Last-Modified-Since
Is the time when the client last modified the resource. The client tells the server. When the client requests the server, the two times are compared ifThe server resource was last Modified longer than the if-modified-since field value
Returns the resource file with the status code 200. Otherwise, the resource is not updated and 304 is returned.
conclusion
- The browser’s caching mechanism, yes
Strong caching takes precedence over weak caching
- Cache-control takes precedence over Expires in strong caches, and some pages don’t even return Expires. Cache-control, which is worth the exact Cache,
Just pass one value, yes, no, no
- If the strong cache does not hit the negotiation cache, the negotiation cache is determined by the cache identifier.
- Etag/ if-none-match has a higher priority than last-modified/if-modified-since, the former is
A unique identifier
By comparison, the latter isTime than
. It’s still a unique identifier, and this time ratio is like an upgraded version of strong cached Expires - The last one said by contrast, so by contrast is
Client and server
We’re gonna run it against each other, soNegotiation cache is network-based
. However, strong Cache is used to Cache identification through cache-control, which does not go through the network, only to see if there is a corresponding field - 304: The server has performed GET, but the file has not changed, return 304
Cache-relevant headers
-
Expires: Indicates the expiration time of a resource
-
Cache-control: Cache Control field, which precisely controls the Cache field
-
If-modified-since: Request header, the last time the resource was Modified, told to the server by the browser
-
Last-modified: The server tells the browser when the response header resource was Last Modified
-
If-none-match: request header, cache resource identifier, told by the browser to the server
-
Etag: Response header, cache resource identifier, told by the server to the browser