Introduction: The HTTP strong cache was introduced before, here continue to introduce HTTP negotiation cache;

What is negotiated cache?

The negotiated cache differs from the strong cache in that the negotiated cache sends a request to the server to determine whether the cache can be used before deciding to use the disk cache, and if so, the browser simply reads the cache and returns it.

Negotiation cache procedure

Negotiated cache flag

Last-Modified & If-Modified-Since

Last-modified: The Last modification time of the currently requested resource returned by the server to the client.

If-modified-since: The client returns last-modified of the Last request as this parameter to the server.

For example:

last-modified: Wed, 28 Apr 2021 18:58:18 GMT
if-modified-since: Wed, 28 Apr 2021 18:58:18 GMT
Copy the code

Last-modified is the absolute time of a server, in seconds, that changes when the server file changes. The drawback of the Last-Modified control cache, however, is that when the file changes less frequently than the s-level, it will not recognize the changes and the client will continue to use the cache, leading to problems with timely updates.

Etag will address this flaw, as described below.

Etag & If-None-Match

Etag: the server returns the hash value generated from the file.

If-none-match: The client returns the etag of the last request as this parameter to the server.

Etag is a hash value generated based on the file. The minimum effective time unit is ms(milliseconds). It resolves last-Modified file changes that are not recognized at levels less than S(seconds). When the service finds that the eTAG value has not changed, it tells the client to use the cache directly.

priority

Etag > last-Modified when both last-Modified and etag exist; That is, last-Modified does not take effect when eTAG exists;

When strong caching is in effect, negotiation caching is not in effect.