Caches can be divided into strong cache and negotiated cache.

  1. When making a resource request, the browser checks whether the Response Headers matches the strong cache. If so, the browser directly reads the cache from the local server without sending a request to the server.
  2. If the strong cache does not match, the server sends a request to the server to determine whether the negotiated cache matches. If the request is matched, the server returns the request without returning resources and tells the browser to read the cache locally. How does the server return the resource directly if it is not hit
  3. Difference: strong cache hit, will not request server, direct request cache; Negotiation cache hit, will request the server, will not return the content, and then read the cache;

Strong cache

Strong caching is divided into Expires and cache-control

An Expires time is equivalent to the server’s time, which is an absolute time.

Expires, which is a string in the GMT format. The first time a browser makes a request, the server returns an Expires header. The next time a request is made, it hits the cache before that time.

Cache-control is a time difference relative to the local computer, which is generally accurate as long as the local time is not modified.

Cache-control, which uses max-age to determine the Cache life cycle in seconds. How to hit the Cache within the life cycle time

Negotiate the cache

Negotiation cache, that isStrong cache expirationNow, butOn the serverConduct on resourcescontrastAfter that, this part of the contentThere is no changeChange back at this timeBack to 304“Indicates that the local cache can continue to be used.

summary