Home > Debian, Debian GNU/Linux, HowTo, Linux, Linux Helps, PHP, Programming Help, somewherein..., Tricks, ubuntu > Website Optimization 01: disable ETag in apache (debian/ubuntu)

Website Optimization 01: disable ETag in apache (debian/ubuntu)

From last few months i am working to optimize our somewhereinblog.net server, because right now we are getting huge amount of hits everyday (1,00,000 + hits). In this series i will describe the tricks that i learned πŸ™‚


On my first post of this searies i will talk about ETag. Before disable this, first we need to know what is ETags. From wikipedia:

An ETag (entity tag) is an HTTP response header returned by an HTTP/1.1 compliant web server used to determine change in content at a given URL. When a new HTTP response contains the same ETag as an older HTTP response, the contents are determined to be the same without further downloading. The header is useful for intermediary devices that perform caching, as well as for client web browsers that cache results. One method of generating the ETag is based on the last modified time of the file and the size of the file.

In certain situations, ETags may not improve the performance of a web application. For instance, some ETag generation schemes incorporate the file’s inode on the system. The file’s inode is unique to the file only on one specific machine. If a site has multiple servers, each with its own copy of the file (i.e. load balancing), then a user’s request for the same file may get served by a different machine. In that case, the inode will almost certainly be different and, if it is used to generate the ETag, it will cause the file to be re-downloaded.

So, this is not always helpfull for all type of sites. Always remember, if you are not using anything, you should not enable or kept enable on server.

Apache by default enable this ETags. We need to disable this to get better performance. Here i am describing the steps for debian and ubuntu linux.

We will take help from mod_header to disable ETags, so first we need to enable the mod_header (apache module)

sudo a2enmod header

sudo /etc/init.d/apache2 restart

this command will enable mod_header. Now open /etc/apache2/apache2.conf with your faviourate browser.

sudo nano /etc/apache2/apache2.conf

then paste the under given code to this apache2.conf file

Header unset ETag
FileETag None

now restart the apache2, and check if it working or not. If every thing OK, then you will not see the etags anymore πŸ™‚

For better understanding i am giving you 2 screenshots.

Before ETag disable


After ETag disable:


If you don’t have root access to server, you still can do this from .htaccess , just copy that code to .htaccess instate of apache conf file.

Ask me if you have any question or problem about ETag.

Views :17418
  1. October 26th, 2008 at 12:59 | #1

    good post. keep it up. very few are aware of the E_TAG things. so welcome and em looking forward for the next post of this series :).

  2. Jordon Bedwell
    November 21st, 2008 at 04:51 | #2

    I find disabling E-Tags for the sake of very little server optimisation is a very ignorant move. Especially in a world where response is everything. This is almost as bad as forgetting far-future dates in the headers, DEFLATE on static files and dynamic pages and putting JS at the bottom of the page. Real administrators can expand clusters and even optimise other parts of the server for the sake of response on the end-user. Disabling these things can impact your sites hits and performance more than disabling will impact stability.

  3. November 22nd, 2008 at 12:07 | #3

    @Jordon: yea it’s bad to ignore/disable etags, but when you are running a single server, all the files are coming from same host every time, then it’s not really necessary to match the etags. you know, by saving a single response for every single file will save your huge server time.

  4. Thirupathy
    July 3rd, 2009 at 02:28 | #4

    hi ,

    thanks for this info. how i will set & remove etag for external images coming from cdn server like akamai.

    help me on this

  5. August 15th, 2009 at 06:11 | #5

    FYI, on Ubuntu 9.04, the following command

    sudo a2enmod header

    should be:

    sudo a2enmod headers

  6. eric jung
    September 4th, 2010 at 00:32 | #6

    This post is extremely misleading. You should almost NEVER disable etags for single-server websites. The etag header prevents browsers from re-requesting a resource unless its “fingerprint” has changed. This leads to a website that loads MUCH faster on subsequent visits.

    For multi-server websites, etag headers are still useful. You simple have to use a more intelligent “fingerprint” than file inodes or last modified time (example: a file checksum, which will be the same across all servers since file contents are the same across all servers, or file version number).

  7. eric jung
    September 4th, 2010 at 00:59 | #7

    test

  8. January 31st, 2012 at 01:03 | #8

    @lavluda
    I am slightly confused by your answer, from the original article I understood that I can keep my etags enabled if I am using only one server, right? Only need to remove them for speed if I am using multiple servers, correct?

  9. January 31st, 2012 at 01:05 | #9

    @ovidiu
    Btw. there is something wrong here, I checked the box to be notified by follow up comments and the confirmation email I got told me I need to confirm that I want to follow your blog for new posts, which I did not check!?
    I’ll check both boxes for now to be sure I am notified of follow up comments.

    • February 11th, 2012 at 15:25 | #10

      ic, i have no idea, i am using jetpack plugin for it.

  1. March 6th, 2010 at 20:15 | #1

%d bloggers like this:
49 queries in 0.536 seconds