when the server receives the request, 200OK last-modified ETag header , the client saves the resource in the Cache and records both of these properties. When the client needs to send the same request, will carry if-modified-since and If-none-match in the request . two x head . Two header values are in response last-modified and the ETag the value of the header. The server uses these two headers to determine that the local resource has not changed, the client does not need to re-download, return 304 Response. The common process is as follows:
The image above is the time to visit Baidu, the black request is to obtain resources, the gray request is to send the validity confirmation, and then next from the cache server to obtain resources.
The following is the header for HTTP requests using cache resources, which can be seenThe response from the cache server and the response header to the resource server for validation.
Request header for the first request:
because the HTTP response sets the date and expires fields to the same value, the cache server does not cache the resource, so it will request the source resource server every time. Max-age set to 0 also allows validation of the source server to be validated every time, rather than a time period.
Verify with the source server that there is a if-modified-since field in the header that tells the server to accept only resources that have been modified since that time, and returns 304 if there is no modification after that time.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HTTP Cache Example