How to enable ETag in Apache Http Server

If your using Apache HTTP Server then you can use it to generate and return ETag for static resources that are served from disk. The Apache Http Server also takes care of comparing the value of If-None-Match header with ETag of the resource and returning either 304 Not modified or 200 OK.

Support for ETag is part of the Apache Core and it is enabled by default. Ex. These are the response headers that i get when i try to access cachesample.gif, which is a static image file on disk from Apache Server

The value of ETag header in this case is combination of three things INode MTime Size

You can configure the behavior of the ETag using the FileETag directive which configures the file attributes that are used to create the ETag (entity tag) response header field when the document is based on a file. (The ETag value is used in cache management to save network bandwidth.) In Apache 1.3.22 and earlier, the ETag value was always formed from the file's inode, size, and last-modified time (mtime). The FileETag directive allows you to choose which of these -- if any -- should be used. The recognized keywords are:

  1. INode : The file's i-node number will be included in the calculation. i-node is the number generated by OS to keep track of the file, it includes things like access level, creation time,... You can configure apache to use only INode by adding this line to httpd.conf

    FileETag INode

    This is screen of how the INode only ETag looks like

  2. MTime: The date and time the file was last modified will be included. You can configure apache to use only Last-Modified date of the file to generate ETag by adding this line to httpd.conf

    FileETag MTime

    This is how my cachecontrol.gif response headers look like when i use MTime for ETag generation

  3. Size: The number of bytes in the file will be included. You can configure Apache to use only size of the file for generating ETag by adding this line to httpd.conf

    FileETag Size

    This screen shot of headers when Apache is configured to use only file Size for calculating ETag

  4. All: All available fields will be used. This is equivalent to: FileETag INode MTime Size

  5. None: You can disable generation of ETag by Apache Http Server by adding this line

    FileETag None

    THis is screen shot of headers after ETag is disabled


Anonymous said...

Hi , The httpd.conf in my case is empty (Apache/2.2.22 ) . Where can I find this configuration ?

ajit patel said...

Impressive! I really like your blog. Thanks for the post.
seo company in nagpur
website services in nagpur


Nice blog..! I really loved reading through this article. Thanks for sharing such
a amazing post with us and keep blogging...
digital marketing services in khammam
seo services in khammam
smm services in khammam

katetech said...

Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
digital marketing services in kothagudem
seo services in kothagudem

katetech said...

Useful Information, your blog is sharing unique information....
Thanks for sharing!!!
php developers in kphb
php developers in ameerpet
php development companies in hyderabad

Anonymous said...

lampung Info

Abhi said...

Thanks for info
Web Design Company in Bangalore
Website development in Bangalore

لولهupvc said...

great post.