Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defined client cache seems to get ignored

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.

like image 528
Yag Avatar asked Dec 05 '11 14:12

Yag


1 Answers

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.

like image 93
penderi Avatar answered Oct 03 '22 18:10

penderi