The principle of 304 status code --- strong cache and negotiation cache

One: Concept

When the cache expires, the browser sends a request to the server to verify whether the cache is valid. If it is valid, the server returns a 304 status code, and 304 mostly appears on requests for static resources.

Two: 304 principle

When the browser initiates the request for the first time, the server will tell the browser when the resource was last modified in the response. When you request the resource again, the browser will ask the server whether the resource has been modified. , the 304 status code will be returned. At this time, the browser will continue to use the local cache resources without resending HTTP requests to the browser, reducing performance consumption.

Three: Expansion

Browser caching: strong caching and negotiation caching

Before sending a request to the server, the browser will first cache the request result and cache ID locally, and store the request result and cache ID locally after sending the request. It is divided into strong cache according to whether it needs to send an HTTP request to the server. and negotiate cache

Negotiation cache:

When the forced replacement fails, the browser will carry the cache identifier to ask the server, and the service area will decide whether to use the cache according to the cache identifier

Negotiation cache only needs to have the following two situations:

Negotiation cache takes effect -- return 304 status code, browser continues to use local cache resources

Negotiate cache invalidation -- return a 200 status code and a new cached result

Guess you like

Origin blog.csdn.net/weixin_71171795/article/details/129392143