Tutorial

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).

Shares:

Leave a Reply

Your email address will not be published. Required fields are marked *