How to Configure ETags to Increase your Sites Performance
What are ETags
ETag, short for an Entity Tag is a response header used for static resources as a cache validator. Knowing how to configure etags will help you increase your sites performance.
How Etags are used
The value of the ETag is used by the browser to determine whether the requested resource can be used from the local cache or must be fetched from the remote server.
An Entity Tag helps reduce server load and increase response time as they help reduce HTTP requests and network bandwidth.
What makes an ETag
An entity tag is a unique identifier for a resource. Traditionally, each entity tag contains three values
- Inode – Files inode number
- MTime – Last modified date and time of the file
- Size – Size of the file in bytes
An example an ETag using all of the above parts may look something like 648077b-2b-525ee9e401fc0. Keep in mind that this will vary depending on the server configuration.
Problem With ETags
The issue with entity tags is the usage on inode value. The inode value differs from server to server. For sites that are served from multiple servers, the entity tag value will always be different. This in turn will invalidate the cache even if the requested resource is an exact same copy with no modifications.
Note: When a copy of a resource served from multiple servers is not recognized as same, the server responds with a 200 status code. If the resource were to be identified as same, the server would have responded with a status code of 304 not modified.
ETags vs Last-Modified
ETags and last-modified headers both serve the same purpose – validate cache. As long as you are using a valid ETag, you can keep both etags and last-modified headers.
If you are using last-modified header, then you can safely remove etags if you want. This will help reduce the header size of a response.
How to configure ETags in Apache
In Apache web server version 2.3.14 and earlier, the default entity tag value used to be
Inode MTime Size
This has now changed, and the new default value is
So, if you using a newer version of Apache, there is no need to configure ETag value. However, for those of you using an older version of Apache, use the following code in the main Apache configuration file or .htaccess file to configure ETtag
FileETag MTime Size
This will remove the inode part from etags which will resolve multiple server issues. After using the above code, an ETag will look like 2b-525ee9e401fc0.
How to configure ETags in Nginx
Good news If you are a Nginx user – you don’t need to do anything. Nginx has no ETag issues.
How to turn off ETags in Apache
Use the following code in the main Apache configuration file or .htaccess file to completely turn of entity tags
How to turn off ETags in Nginx
Use the following code in the Nginx configuration file to completely turn of entity tags