Monday, May 14, 2012

ETags and disable ETags with .htaccess

About Etags (text fom Wikipedia):
An ETag, or entity tag, is part of HTTP, the protocol for the World Wide Web. It is one of several mechanisms that HTTP provides for cache validation, and which allows a client to make conditional requests. This allows caches to be more efficient, and potentially saves bandwidth, as a web server does not need to send a full response if the content has not changed. ETags can also be used for optimistic concurrency control, as a way to help prevent simultaneous updates of a resource from overwriting each other.

An ETag is an opaque identifier assigned by a web server to a specific version of a resource found at a URL. If the resource content at that URL ever changes a new and different ETag is assigned. 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.

To setup ETags on your server, use following htaccess snippet:

FileETag MTime Size
<ifmodule mod_expires.c>
  <filesmatch "\.(jpg|gif|png|css|js)$">
       ExpiresActive on
       ExpiresDefault "access plus 1 year"
   </filesmatch>
</ifmodule>

Sometimes you want to be sure to have ETags disabled. To disable ETags, make sure to include following snippet in your .htaccess file.

Header unset ETag
FileETag None

No comments:

Post a Comment