IIS 7.5 remove etag headers from response

15,705

Solution 1

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.

Solution 2

For those of you that come across this answer in search of the same solution but for IIS 8 or IIS 8.5, here is what I've come up with. 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>
Share:
15,705

Related videos on Youtube

Grofit
Author by

Grofit

Updated on June 26, 2022

Comments

  • Grofit
    Grofit almost 2 years

    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
    Grofit over 12 years
    Will give it a try, and if it works, I will crown you a king amongst men!
  • Nathan Fox
    Nathan Fox over 12 years
    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.
  • peter3
    peter3 over 12 years
    god dam! you're right! kudos to you for a solution on a super irritating problem
  • Grofit
    Grofit over 12 years
    Sorry completely slipped my mind this weekend, will give it a go tonight and then report back.
  • Jason Weber
    Jason Weber over 11 years
    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!
  • FiniteLooper
    FiniteLooper almost 10 years
    This DOES work, but to be clear the above code must be placed inside the <system.webServer> node, and you must install the IIS Rewrite Module: iis.net/downloads/microsoft/url-rewrite
  • LeftyX
    LeftyX almost 10 years
    This is the only solution which seems to work. Great!
  • RacerNerd
    RacerNerd over 9 years
    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?
  • RBT
    RBT almost 8 years
    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
    RBT almost 8 years
    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.