Search code examples
asp.netcachingpagespeed

Controlling browser caching with ASP.NET and IIS 7.5


Google PageSpeed suggests the following this for my website as a high priority.

The following cacheable resources have a short freshness lifetime. Specify an expiry of at least one week in the future for the following resources:

And suggests further reading.

I am using Windows Server 2008 r2, .net framework 4.0, asp.net and IIS 7.5. How can I increase the cache expiry for some files?

I've tried the following web.config, but it doesn't work.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <sessionState mode="Off" />
    </system.web>
    <system.webServer>
        <staticContent>
          <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00" />
        </staticContent>
    </system.webServer>
</configuration>

Solution

  • Are you sure this is not working. I just knocked up a simple page with a single image as a test. Added your config section exactly and checked in firebug.

    Here are the headers.

    enter image description here

    Looks ok to me.