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 headerDetermine 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 anotherrequest headerVerify that the resource matches the negotiated cache, calledhttpThen 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;
  • whenctrl+f5When the page is forced to refresh, it is loaded directly from the server, skipping the strong cache and negotiated cache.
  • whenf5When 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.1The specification for strong caching utilizes itmax-ageValue to determine the maximum lifetime of the cache resource in seconds.

Negotiate the cache

  • Last-ModifiedThe value is the last update time of the resource, with the serverresponseReturn, 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.)
  • ETagA unique identifier that represents the content of the resource, along with the serverresponseReturn, only based on whether the contents of the file have changed)
  • If-None-MatchThe server compares the header of the requestIf-None-MatchWith the current resourceETagConsistency determines whether the resource has been modified between requests. If not, the negotiated cache is hit.)