By removing the ETag header, you disable caches and browsers from being able to validate files, so they are forced to rely on your Cache-Control and Expires header. Basically you can remove If-Modified-Since and If-None-Match requests and their 304 Not Modified Responses.
Entity tags (ETags) are a mechanism to check for a newer version of a cached file.
Easy Apache Speed Tips Articles
- Turn On Compression
- Add Future Expires Header
- Add Cache-Control Headers
- Turn Off ETags
- Remove Last-Modified Header
- Use Multiple SubDomains
Please don’t turn off ETags and Last-Modified headers for your .html files, leave one of them ON. (I use Last-Modified for .html).
Turn ETags Off
This goes in your root .htaccess file but if you have access to httpd.conf that is better.
This code uses the FileETag and the Header directive to remove all ETags from being sent.
Header unset ETag FileETag None
Example ETag Request and Response
Notice that the ETag performs the same service that Last-Modified header performs.
Response for /i/yahoo.gif
HTTP/1.1 200 OK Last-Modified: Tue, 12 Dec 2006 03:03:59 GMT ETag: "10c24bc-4ab-457e1c1f" Content-Length: 12195
Later, if the browser has to validate a component, it uses the If-None-Match header to pass the ETag back to the origin server. If the ETags match, a 304 status code is returned reducing the response by 12195 bytes for this example.
GET /i/yahoo.gif HTTP/1.1 Host: us.yimg.com If-Modified-Since: Tue, 12 Dec 2006 03:03:59 GMT If-None-Match: "10c24bc-4ab-457e1c1f" HTTP/1.1 304 Not Modified
With ETags
The problem with ETags is that they typically are constructed using attributes that make them unique to a specific server hosting a site. ETags won’t match when a browser gets the original component from one server and later tries to validate that component on a different server, a situation that is all too common on Web sites that use a cluster of servers to handle requests. By default, both Apache and IIS embed data in the ETag that dramatically reduces the odds of the validity test succeeding on web sites with multiple servers.
Without ETags
Related Articles
10.10.07 at 5:37 pm
Note that this page provides the opposite advice that Yahoo developers are giving in the new book http://www.oreilly.com/catalog/9780596529307/ by Steve Souder, modulo the problem with etags including inode information when using multiple web servers.
10.10.07 at 7:28 pm
Steven, The Yahoo Developer Best-Practices Exceptional Performance Group are the creators of the yslow extension for firebug that recommends removing them.
But you can’t just remove them or keep them because some blogger or new book says too. You have to do your own research and understand for yourself what the best-practice is.
Etags exists only as an alternative to checking the Last-Modified header as a method of validating the freshness of a file to determine whether it should be re-requested and emptied from the cache, or whether it should stay in the cache.
Even though all proxies are supposed to be following a defined set of standards for handling these types of data, not all do. But one thing is true, if you make sure that you provide at least one valid way for the proxy/client to determine how long the file should be cached, everything else is redundant and was created as an alternative not as a way to clog up the net with unneccessary HTTP headers.
11.13.07 at 2:16 am
How do you turn off etags just for static files like images?