An entity tag (ETag) is an HTTP header used for Web cache validation and conditional request from browsers to resources. The value of an ETag is an identifier that represents a specific version of the resource. Additionally, ETags help prevents simultaneous updates of a resource from overwriting each other. Example of ETag header is
Note :The value of the ETag header must be in double-quotes.
Working of ETag
- The server receives an HTTP request for a particular resource.
- The server generates a response and attached an ETag header. For Eg: ETag: “response_version1”.
- The server sends the response with the above header with the status code 200. Then the application represents the resource and at the same time caches the resource copy along with header information.
- Later the same application makes another request for the same resource with following conditional request header: If-None-Match: “response_version1”
- On receiving the request for the resource along with the ‘If-None-Match’ header, the server-side logic compare the current value of the ETag identifier on the server-side and the one which is received in the request header.
- If the request’s If-None-Match is the same as the currently generated value of ETag on the server, then status code 304 (Not Modified) with the empty body is sent back and the application uses the cached copy of the resource.
- If the request’s If-None-Match value doesn’t match the currently generated/assigned value of ETag (say “response_version2”) for the same resource then the server sends back the new content in the body along with status code 200. The ‘ETag’ header with the new value is also included in the response. The application uses the new resource and updates its cache with the new data.
Generating ETag Value
That’s entirely up to the application to generate it as it wants. It can be created and updated manually or can be auto-generated. Common methods of its auto-generation include using a hash of the resource’s content or just a hash of the last modification timestamp. The generated hash should be collision-free.
Validation of ETag value
It is just comparison of two values. It is divided into 2 parts
- Strong Validation
- Weak Validation
The different resource representations are byte-for-byte identical. This is the default validation of ETag and no special directive is used for it.
The two resource representations are semantically equivalent. For e.g. the current date displayed on the page might not be important for updating the entire resource for it.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- How slow HTTP can knock down a server?
- How to Start a Career in Software Testing - A Complete Guide!
- Virtualization to Promote Green Computing
- Learning Vector Quantization
- Routing requests through Load Balancer
- Introduction To Classic Security Models
- What is Mobile Cloud Computing?
- Stable Coins - Catalyst to Cryptocurrency
- Self Organising Maps - Kohonen Maps
- The illusions in Virtual Reality
- A Quick Overview to Computer Vision
- Applications of Computer Vision
- What is AMR(Adaptive Multi-Rate Codec)?
- What is E-paper Technology in Amazon’s Kindle?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jyash97