Browser Cache policy

  • The browser cache is divided intoStrong cacheandNegotiate the cacheThey are all passedHTTP packet cache identifier

Strong cache

  • The cache identifiers for strong caching areExpiresCache-Control
  • Expires isHTTP / 1.0If the client’s time is less than Expires, use the cachehttp1.1Expires has been replaced by the cache-control field.Cache-ControlAre 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-MatchEtagisServer request responseIs returnedUnique identification of the current resource. When the client sends the request,If-None-MatchWill carry onThe last timeThe 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 200
  • Last-Modified/ If-Modified-Since: Last-ModifiedisThe server returns the last time the resource was modified. Returned by the server to the client.Last-Modified-SinceIs 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 valueReturns the resource file with the status code 200. Otherwise, the resource is not updated and 304 is returned.

conclusion

  • The browser’s caching mechanism, yesStrong 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 isA unique identifierBy 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 isClient and serverWe’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