6

I'm not sure what I'm doing wrong but despite of everything I've tried, I don't seem to be able to get the clients to cache my static resources.

In my web.config, I've added the following entry:

  <staticContent>
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
  </staticContent>

According to the documentation, this should send a response header to the client browser to let it know we want to keep static content cached for 30 days.

If I use fiddler to see what the client is receiving, it looks like my web.config addition gets ignored completely.

Below is what fiddler is reporting:

Cache-Control: no-cache
Date: Mon, 05 Dec 2011 14:09:44 GMT
Expires: -1
Pragma: no-cache
Vary: Accept-Encoding

I don't have any headers in IIS overriding this so I'm not sure what is it that I am missing. Any help would be greatly appreciated.

Yag
  • 546
  • 2
  • 7
  • 12

1 Answers1

6

I cracked this but it took a while. You're trying to force 304s from the server (no change). It differs with IIS versions.

It's best achieved by having all you're static content in one directory (e.g. content so you'd have /content/css /content/js etc)

Then you just have to ensure everything under that directory doesn't expire for, say, 30 days.

IIS7

Much easier. Easiest way - add a web.config to the content directory referred to above. This web.config will have just the expires directive:

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

IIS6

You'll need to manipulate the metabase. It's not XML in IIS6, follow the instructions here: IIS6 ETags metabase commands

We used both the above and simple viewing of firebug shows 304s coming through.

penderi
  • 8,673
  • 5
  • 45
  • 62
  • First of all, thanks for your help. I do get the 304s as you point out above but adding the web.config in the content folder didn't make a bit of a difference. I've tried adding the new web.config to the /Content folder and ended up getting 500 errors (_there is a problem with the resource you are looking for, and it cannot be displayed_). I've also moved it to the folder where the resource is: /Content/css and the css file was now retrieved successfully but with the no-cache header again. – Yag Dec 05 '11 at 16:05
  • Looks like this may help http://stackoverflow.com/questions/5385714/deploying-website-500-internal-server-error routing maybe.... – penderi Dec 05 '11 at 16:41