An “Entity Tag”, or ETag, is part of HTTP protocol used in conditional GET requests, incorporating caching into the HTTP protocol itself. ETags are meant as an additional way to validate a local cache. The idea is to attach a bit of metadata to the header of each request to uniquely identify a specific version of a resource, allowing the client machine to know if a resource has been changed. When the client makes subsequent requests for the same resource it sends the same ETag in the request header, which the server uses to determine if the resource has changed since it was last accessed. If it has not, it sends back a small “304 Not Modified” response, telling the client to just used the locally cached version instead.
Most performance resources (with the exception of YSlow) recommend disabling ETag data in your requests to make each request smaller. It’s similar in concept to removing image metadata, since this ETag data is optional within the HTTP protocol. There’s more to it with ETags, though. Disabling ETags forces the browser to use the “Expires” cache validation method, meaning it doesn’t send a new request to check if the local cache is invalid, it just needs to check the date. So fewer requests need to be sent for cached pages, and “no request” is faster than an “HTTP 304” request.
But exactly how much load time will you be saving by removing this data? Exactly how much does each request shrink by when ETags are removed? Is it worth it to disable ETags? The answers to those questions are more complicated than we initially thought.
How to Implement
Disabling ETags is actually pretty easy. If you are using an Apache server, it’s simply a matter of typing a few extra lines into your website’s .htaccess file:
Header unset ETag
FileETag None
Benefits
If you remove ETags, you are removing data from each HTTP request, so each request should be smaller in size, theoretically making everything load faster. This should also reduce the number of conditional GET requests sent to the server. So let’s look at exactly how much data we saved by disabling ETags:
About 0.2% decrease in bytes in for each page. Less than a kilobyte per page. That’s hardly even worth note! What’s more, number of requests wasn’t affected at all. How much could that possibly decrease load ti-
Oh. That’s actually pretty significant. A 9% drop in load time across all pages on average. While it may not be a massive increase in page speed, it’s still a noticeable drop in load time. It would appear, then, that disabling ETags is the way to go for a page speed increase.
That’s what I would be saying if caching wasn’t important. You see, testing caching speeds was outside the scope of these tests. We’ll come back to this at some point with a better setup to get better metrics on the impact ETags have on both page speed and caching, but for this experiment all we can say is that we saw an increase in first-view page speed by taking them away.
Drawbacks
As far as I can tell, most places suggest disabling ETags is for a couple of reasons:
- There exist other methods to determine if a cached object is valid or not (such as “Last Modified” and “Expires”), and some places see ETags as superfluous.
- Incorrectly configured ETags often return an invalid response when a website is spread across multiple servers. This is because if a resource is requested on one server, the ETag is specific to that server. If the same resource is then accessed from a different server, the ETag is now invalid and the resource is downloaded unnecessarily.
With some setups, and when configured properly, ETags can provide a great supplementary method of cache validation to Last Modified and/or Expires. Taking them away can lead to inefficient caching, meaning slower cached pages. ETags are good for caching. It’s just that it’s much easier to remove them altogether for a small performance boost than to set them up properly for a larger one.
Bottom Line
Taking away ETags seems to have a positive impact on initial page speed. By default, ETags are improperly configured for use on websites spread across multiple Apache or IIS servers. If you’re using a multi-server setup, it’s much easier to remove them altogether than to find a good configuration setting for them to work properly.
If your setup is on a single server, like ours, though, disabling ETags is a way to get a small performance boost out of your pages. However, we have not tested what impact removing them has on caching. That is the subject of another test for a later time.