HTTP response last-modified and ETag

Source: Internet
Author: User

HTTP response last-modified and ETag
[Date: 2008-06-16] Source: [Font: Big Small]

Basic knowledge
   1) What is "last-modified"?
When the browser requests a URL for the first time, the server-side return status is 200, the content is the resource you requested, and there is a last-modified attribute that marks the last time the file was modified at the end of the service period, similar in format:
Last-modified:fri, 2006 18:53:33 GMT
When the client requests this URL for the second time, according to the HTTP protocol, the browser transmits the If-modified-since header to the server, asking if the file has been modified after that time:
If-modified-since:fri, 2006 18:53:33 GMT
If the server-side resource does not change, the HTTP 304 (not Changed.) Status code is returned automatically, and the content is empty, which saves the amount of data transferred. When the server-side code changes or restarts the server, the resource is re-emitted, similar to when the first request is returned. This ensures that the resources are not duplicated to the client, and that the client is able to get the latest resources when the server changes.
   2) What is an "Etag"?
The HTTP protocol specification defines the etag as the entity value of the requested variable (see-section 14.19). Another argument is that the ETag is a token that can be associated with a Web resource. A typical web resource can be a Web page, but it may also be a JSON or XML document. The server is solely responsible for judging what the token is and what it means, and transmitting it to the client in the HTTP response header, which is the format returned by the server side:
ETag: "50b1c1d4f775c61:df3"
The client's query update format is this:
if-none-match:w/"50b1c1d4f775c61:df3"
If the etag does not change, it returns the status 304 and does not return, which is the same as last-modified. I test the etag is mainly in the breakpoint download is more useful.
   how do last-modified and etags help improve performance?
Smart developers will use the HTTP header for Last-modified and ETAGS requests, which can take advantage of caching by clients such as browsers. Because the server first generates the LAST-MODIFIED/ETAG tag, 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 a last-modified/etag to a.
    3. The client presents the page and caches the page along with Last-modified/etag.
    4. The customer requests page A again and passes the Last-modified/etag that the server returned when the last request was sent to the server.
    5. The server checks the last-modified or ETag and determines that the page has not been modified since the last client request, directly returning the response 304 and an empty response body.
    • 55
    • Top

HTTP response last-modified and ETag

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.