What are Entity Tags?
An entity tag (ETag) is an HTTP header that is used to validate that the cache exists locally is the same as the resource that exists on the server. It is a unique identifier assigned to a specific version of the resource on the server.
ETags allows the browser to make the conditional request to the servers. The condition is that they have been updated since the last fetching of the resource by the browser.
- How eTags work?
- Anatomy of ETag
- Problem with ETags?
- How to configure the Entity tags for Multiple Servers?
- Remove eTags
How eTags work?
To understand how eTags works, you have to know how the browser fetches the pages.
You can read in detail how HTTP and HTTPS requests are made to get the resources from the server to the client’s screen.
In short, the browser sends the request to the web server, asking for the resources user asks for. Then the webserver read it and respond with the resources. The browser made those files accessible for the user.
Where the eTags enters?
The entire process — sending the request and receiving the response — should be short to speed up the loading of the pages.
eTags helps in improving the page speeds. The same image or file that is on the webserver is also saved locally due to caching.
The eTags compare the file that is saved locally to that one that is on the webserver. If they are the same, the response given by the response does not consist of that file. That file is fetched from the local storage.
This puts less load on the response; the web page opens faster.
But the condition is that the resources at the webserver end have not been updated.
Anatomy of ETag
A traditional ETag is made up of three components, that makes it a unique identifier for each file:
The example of ETag:
However, the structure could change and depend on whether the ETag has strong validation or weak validation.
A strong validation in ETag means that the content of the two resources (locally saved and on the server) matches byte-for-byte. It means they are completely identical to each other.
A weak validation in ETag means that the content of the two resources (locally saved and on the server) are semantically equivalent. Both o of the resources serve the practical purpose, but they are not a byte-by-byte copy of each other.
What is the problem with ETags?
The problem with ETags is that they can only be used on the site that fetches the resources from the single server.
That’s why the websites that deliver the resources from multiple servers use Apache or IIS. Hence, the entity tags do not work well for them.
The unique identifier stamp on the eTag by one server would not be recognizable by the different server, and the response would be 200 instead of 304 Not Modified. This means the content would not be fetched from the local storage, but the browser would request it directly from the origin.
Therefore, it will reduce the loading speed of the site, and as well provide the poor user experience to the visitor.
How to configure the Entity tags for Multiple Servers?
Best practice to configure the entity tags for Multiple servers for website running on Apache is to remove the INode portion of the Etag.
Modify the snippet by adding this code to your httpd.conf file:
<directory /usr/local/httpd/htdocs> FileETag MTime Size </Directory>
With this code, the INode would be removed from the Entity tags. Without the Server component, the Etags can perform its function properly.
Remove ETags Entirely
Another solution to the ETags problem is to remove the Etags entirely.
To remove the entity tags from Apache, add the following code to the configuration file:
Header unset Etag File ETag none
This will reduce the size of the header. After removing the Etag, the site has to depend on other methods of site optimization.
ETags performs a simple function, but they can speed up the site a lot if appropriately set.
However, if they are not correctly set up, Etags are added burdens.
If there are any questions, leave them in the comments box.