28

I know this question has been asked alot of times, however most of them were in 2009-2010.

I am pretty sure a while back a project I was working on removed them, however I cannot find any way to remove them at the moment.

So has there been any advances in this field? It seems crazy that microsoft has made IIS to not be able to easily configure these headers.

Currently have tried:

  • Adding a blank etag header to the web.config
  • Adding an etag with quotes inside to the web.config
  • Adding a blank etag header directly through IIS
  • Adding a custom module which removes an etag on BeginResponse
  • Same as above but for EndResponse
  • Same as both above but instead of removing an etag, make it empty

I hear there is an ISAPI filter you can get to remove them, but I cannot find it anywhere, and have no experience in writing one from scratch but may end up being the only way to do it.

Just so there is some reason why I want to remove Etags for everything. I let the clients cache everything (expires & last-modified) so once my static files are gotten from the server it never needs to query the server again until it expires. As if you use Etags you still need to make a request to the server for each file to find out if the tag still matches. So using the client cache you only make requests for the content you need.

I also have a versioning system in place so when a change happens the static content is then referenced as my.js?12345 rather than my.js?12344. Anyway the point is I currently believe removing Etags will greatly improve one of the bottlenecks on my current project.

Grofit
  • 17,693
  • 24
  • 96
  • 176

2 Answers2

54

You can use the IIS Rewrite Module 2.0 to remove the ETag. The following rewrite rule should do it:

<rewrite>
   <outboundRules>
      <rule name="Remove ETag">
         <match serverVariable="RESPONSE_ETag" pattern=".+" />
         <action type="Rewrite" value="" />
      </rule>
   </outboundRules>
</rewrite>

You can see an example image of the rule configuration in IIS Manager on my blog.

Nathan Fox
  • 4,023
  • 1
  • 23
  • 18
  • 3
    Will give it a try, and if it works, I will crown you a king amongst men! – Grofit Nov 11 '11 at 12:51
  • 3
    Please make sure to clear your browser cache, you might be pulling from your cache. I had the same issue. I'm sure it works, I've implemented it on my blog and you should not see ETags. – Nathan Fox Nov 11 '11 at 15:37
  • 1
    god dam! you're right! kudos to you for a solution on a super irritating problem – peter3 Nov 11 '11 at 15:52
  • Sorry completely slipped my mind this weekend, will give it a go tonight and then report back. – Grofit Nov 14 '11 at 11:49
  • 1
    It worked for me once I cleared my browser's cache! It bumped my YSlow score up 3 points, and I get no ETag errors anymore. Thank you very much @Nathan Fox! Appreciate you sharing your knowledge! – Jason Weber Nov 06 '12 at 22:11
  • 2
    This DOES work, but to be clear the above code must be placed inside the `` node, and you must install the IIS Rewrite Module: http://www.iis.net/downloads/microsoft/url-rewrite – Chris Barr Jul 15 '14 at 18:39
  • This is the only solution which seems to work. Great! – LeftyX Jul 23 '14 at 13:07
  • I am working in IIS 7. The only thing this didn't work for was the favicon.ico file. Is there any way to specifically address this file? – RacerNerd Sep 03 '14 at 23:42
14

For IIS 8 (and onward)

Thank you to this post on blogs.iis.net for pointing me in the right direction.

Reference: clientCache on the IIS documentation website.

In your web.config, add:

<configuration>
    <system.webServer>
    ...

        <staticContent>
            <clientCache setEtag="false"/>
        </staticContent>

    ...
    </system.webServer>
</configuration>
MeSo2
  • 450
  • 1
  • 7
  • 18
Vince Horst
  • 4,134
  • 1
  • 20
  • 33
  • Ohh...that's IIS 8 onwards. I was trying it in IIS 7.5 :( only to get error `Unrecognized attribute 'setEtag'`. Works like a charm for IIS 8.0 onwards. I tested it on IIS 10.x – RBT Jul 01 '16 at 03:04
  • At most of the places I was reading that it is simply impossible to configure web server to stop emitting ETags. Glad to see your post. – RBT Jul 01 '16 at 03:09
  • and be sure to remove any manually added ETag entries in HTTP Response Headers – MeSo2 Jun 29 '23 at 20:45