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, but last-modified is the HTTP header sent by the server to the client, if-modified-since is the header sent by the client to the server. You can see that when you request a local cache page again, the client sends the last modified timestamp of last-modified sent from the previous server back through the IF-modified-since header to the server for verification, this timestamp is used to determine whether the client page is the latest. If it is not the latest, new content is returned. If it is the latest, then, 304 is returned to inform the client that the page of the local cache is the latest, so the client can directly load the page from the local, so that the data transmitted over the network will be greatly reduced, it also reduces the burden on the server.
If-None-match, IT and etags (the HTTP protocol specification defines etag as the "entity value of the requested variable", or a mark that can be associated with Web Resources) it is often 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 as good as the resource MD5.
the working principle of etags and if-None-match is to add etags in HTTP response. When the client requests the resource again, if-None-match information (etags value) will be added to the HTTP request ). If the etags of the server authentication resource are not changed (the resource is not changed), a 304 status is returned; otherwise, the server returns the 200 status and the new etags.
How does etag help improve performance?
A smart server developer will use the "if-None-match" header of etags and get requests together, so that the client (such as a browser) can be used for caching. Because the server generates etag first, the server can use it later to determine whether the page has been modified. Essentially, the client sends this mark back to the server and requires the server to verify its (client) cache.
the process is as follows:
1. The client requests a page ().
2. The server returns to page A and adds an etag to page.
3. The client displays the page and caches the page together with etag.
4. The customer requests page a again and sends the etag returned by the server in the last request to the server.
5. the server checks the etag and determines that the page has not been modified since the last client request. The server returns the response 304 (not modified -- not modified) and an empty response body.
reference page: http://www.kuqin.com/web/20080513/8442.html