Cache-Control Header & Browser Caching IIS7

compressioniis-7

I am using Google Page Speed on my website in IIS7 and I was wondering how to set

Leverage browser caching – The following resources are missing a cache expiration
Leverage proxy caching – Consider adding a "Cache-Control: public" header to the following resources.

I am using doDynamicCompression in my web.config and little confused how to set these ? Hoping for some help

Note: Reference being used http://www.iis.net/ConfigReference/system.webServer/httpCompression

Best Answer

I found in a few of my tests, I didn't have to do the httpCompression options, just the urlCompression tags.

<configuration>
  <system.webServer>
    <urlCompression doDynamicCompression="true" />
  </system.webServer>
</configuration>

You can achieve the same by going through the UI, and setting the option there, and it'll write the above to your web.config for you. This is under Site\Compression "Enable dynamic content compression" (Static option is usually enabled by default).

The same applies for client caching, but IIS appears to only apply this to static content. This is under Site\HTTP Response Headers\Set Common Headers, and you can enable the web content expiration there. Or the web.config version:

<system.webServer>
  <staticContent>
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
  </staticContent>
</system.webServer>

This sets it for 7 days. When combined, Google's Page Speed FireFox plugin it stops complaining about compression, and browser caching.