If-modified-since & If-none-match
if-modified-since, like last-modified, is the HTTP header used to record the last modification time of the page, except that last-modified is the HTTP header sent by the server to the client, and If-modified-since is the header that the client sends to the server, and as you can see, the client sends the previous server side through the If-modified-since header when it requests the locally existing cache page Last-modified The last modification timestamp sent back, this is to let the server side to verify, through this timestamp to determine whether the client's page is up-to-date, if not up-to-date, then return the new content, if it is up to date, then return 304 to tell the client that its local cache page is up-to-date, So the client can load the page directly from the local, so that the data transmitted on the network will be greatly reduced, but also reduce the burden on the server.
If-none-match, it and Etags (the HTTP protocol specification defines the etag as the entity value of the requested variable, or a token that can be associated with a web resource) is commonly used to determine whether the current requested resource has changed. Similar to last-modified and Http-if-modified-since. But the difference is that last-modified and http-if-modified-since only judge the last modification time of the resource, and Etags and If-none-match can be any attribute of the resource, not the MD5 of resources, etc.
Etags and If-none-match work by adding etags information to HTTP response. When the client requests the resource again, the If-none-match information (the value of etags) is added to the HTTP request. If the server verifies that the etags of the resource has not changed (the resource has not changed), it will return a 304 state, otherwise the server will return a 200 status and return the resource and the new etags.
How does the ETag help improve performance?
Smart Server developers will use the "If-none-match" header of the etags and get requests to take advantage of the caching of clients such as browsers. Because the server first generates an etag, the server can later use it to determine if the page has been modified. Essentially, the client requires the server to validate its (client) cache by passing the token back to the server.
the process is as follows:
1. The client requests a page (a).
2. The server returns page A and adds an etag to a.
3. The client presents the page and caches the page along with the ETag.
4. The Customer requests page A again and passes the ETag returned by the server to the server at the time of the last request.
5. The server examines the ETag and determines that the page has not been modified since the last client request, directly returning response 304 (unmodified--not Modified) and an empty response body.
One HTTP if-modified-since & If-none-match