Cache Cache and strong negotiation - finale

Browser cache means the browser user has recently requested resource've stored on the local disk. By caching, you can reduce the number of browser and server communicate, improve site performance. Browser cache and cache into strong negotiation cache.

Strong Cache

Introduction

When the browser requests a resource file, it first determines whether the cache hit strong. The header information of the resource buffer, and cache-control based expires field strength is determined whether a cache hit, hit if the resource is acquired directly from the cache, return a status code 200, no further initiates a request to the server.

The relevant status code

200

Related Fields

Expries

This field is at http1.0 specification, GMT time string format which is an absolute time, such as Wen, 18 Mar 2020 17:25:00 GMT, if the time before the request is transmitted value, it is determined strong cache hit.

Cache-Control

http1.1 specification when the relevant field has five attributes can be set:

max-Age: it is a number that represents the number of seconds, the maximum relative time for a buffer. If set Cache-Control:max-age=500, the last from the resource calculated from the time server acquired expires after 500 seconds.

pubilc: browsers and proxy servers can cache resources.

privite: Only the browser can cache, the proxy server can not cache.

no-cache: can not use strong cache, the cache can use negotiation.

no-store: All caches are not available.

Cache consultation

Introduction

If the browser useless cache hit strong, it will continue to determine whether the cache hit consultations. If the cache hit consultation, the status code 304 is returned, on behalf of the existing resources, resources taken directly from the cache, no longer initiate a request to the browser; otherwise, it will re-request the resource to the browser.

The relevant status code

304

Related Fields

Etag/If-None-Match

Etag resource is a unique identifier, the identifier is changed when the resource will change, which is a hash value is encoded. When a browser for the first time to access a resource, the resource will be returned with a Etag identifier browser to access the resource again, the request header will appear with a If-None-Match field, its value is Etag value last returned. Then the If-None-Match Etag with the new checksum to see if the same, if they are consistent, if they are consistent, then determine if the last-modefied consistent; if not, the re-request server resources.

Last-Modified/If-Modified-Since

Is a Last-Modified of time in GMT format string representing the resource was last modified. When a browser for the first time to access a resource, the resource will be returned with a Last-Modified identifier browser to access the resource again, the request header will appear with a If-Modified-Since field, it's last-Modified value is the value of the last to return. Then the If-Modified-Since the new Last-Modified be verified to see if the same, then the cache hit consultations.

Etag Last-Modified and differences
  1. Etag better than the Last-Modified. Last-Modified is the smallest unit of time in seconds, if a file is changed several times in one second, then their Last-Modified fact is not reflected changes, but every time Etag changed to ensure accuracy.
  2. In performance, to be inferior Etag Last-Modified, Last-Modified only after all the recording time, and requires a server Etag a hash value calculated by the algorithm.
  3. On the priority, priority servers check Etag.

Verify flowchart

Guess you like

Origin www.cnblogs.com/zhoulixiangblog/p/12519327.html