HTTP ETag Explained

An ETag to entity tag, is a part of HTTP protocol, the protocol of the World Wide Web. ETag is the one of the several mechanisms for cache validation and instruct browser to make conditional request.

This allow caches to be more efficient and saves the bandwidth, as web server does not need to provide the full response header if the file was not changed.

An ETag is an opaque identifier assigned by the web server to each resource of the page at any URL. If resource files changes then web server will assign the new ETag for that resource.

Used in this manner ETags are similar to fingerprints, and they can be quickly compared to determine if two versions of a resource are the same or are different.

Comparing ETags only makes sense with respect to one URL—ETags for resources obtained from different URLs may or may not be equal and no meaning can be inferred from their comparison.

Deployment risks

The use of ETag is and options ( not mandatory as with some other HTTP Header ). The method by which ETags are generated is never been declared in HTTP protocol specification.

Strong and weak ETag validation

The ETag mechanism supports both strong validation and weak validation. They are distinguished by the presence of an initial “W/” in the ETag identifier, as:

“123456789” — A strong ETag validator
W/”123456789″ — A weak ETag validator

In normal usage, when URL retrieve, Web Server will return the resources along with the corresponding ETag value for that resource, which will be placed in HTTP Response Header E-tag Field:

ETag: “686897696a7c876b7e”

The client will catch those resources along with the ETag value. Later if client will request the same URL again, the client will pass the saved ETag for the particular resource in “If-None-Match” header. which is looks like below:

If-None-Match: “686897696a7c876b7e”

On subsequent request web server will check the Browser cached ETag value which is found in If-None-Match header and browser’s resource ETag. If both ETag values matched then web server simply give the 304 Not Modified Status code which tell the browser to load the content from the cache. And if ETags are not matched then browser will return whole response along with new ETag value for that resource.
To enable the ETag you can use the below code in .htaccess file.

FileETag MTime Size

ExpiresActive on

ExpiresDefault “access plus 1 year”

ETags can be disabled by placing the below code in .htaccess file.

Header unset ETag
FileETag None

ETags may be flushed by clearing the browser cache (but browser implementations may vary).

About the Author: Avinash

Experienced full stack freelance web developer with a track record of producing excellent results for 11+ years. Excellent communication and collaboration skills, managing with a team of 20+ people. I’m motivated to make a positive impact on your revenue through the customer web portal development project.

7 Comments

  1. Alex March 25, 2011 at 10:50 pm - Reply

    Hi, really nice post, in my post http://alexsotob.blogspot.com/2011/03/makoto-no-kokoro-wo-shiru-wa-mori-no.html I talk about using ETag with Spring Framework, your post is nice because it talks more about the theory of Etags.

  2. […] HTTP ETag Explained […]

  3. […] HTTP ETag Explained […]

  4. […] To know more about the eTag, you can visit this link. […]

  5. […] ????? ?????? ? eTag ??????, ?? ?????? ???????? ??? ??????. […]

  6. […] To know more about the eTag, you can visit this link. […]

  7. […] know more about the eTag, you can visit this link. Conclusion There are many more tips and tricks to go with this, but I’ve tried my best to present […]

Leave A Comment

FREE QUOTE

Do you need help with services? Request a free quote to get in touch.