2

I have to set expiration for my static files of my application in IIS 7. Using the dialog below: I set it to 10 days.

enter image description here

But when I look at my page analysis using PageSpeed add-on in Chrome, I see that there is no expiration on the files.

enter image description here

Do I have to do something else in my application's configuration too?

2 Answers 2

2

Check out the staticContent element of web.config:

  <system.webServer>
    <!-- StaticContent requires that the machine config section be unlocked: appcmd unlock config /section:staticContent-->
    <staticContent>
      <clientCache cacheControlCustom="private" cacheControlMode="UseMaxAge" cacheControlMaxAge="0.02:00:00" />
    </staticContent>
  </system.webServer>

http://msdn.microsoft.com/en-us/library/ms689506%28v=vs.90%29.aspx

http://www.iis.net/configreference/system.webserver/staticcontent/mimemap

3
  • I add the part you suggested but nothing changes. (it says "expiration not specified" for the two .js files in my Data folder.)
    – xkcd
    Nov 26, 2012 at 15:10
  • 1
    I've verified that this does indeed work. Did you unlock the machine.config section?
    – Greg Askew
    Nov 26, 2012 at 18:25
  • Ooh! I missed the unlocking part. You're right, it works like a charm! Thanks for your help.
    – xkcd
    Nov 27, 2012 at 6:50
1

This setting in IIS controls the expiration of the page returned and not the other resources that the page includes and attempts to load, in your case external JS files. If you check the expiration tag for the page it should show an expiration date.

The IIS setting you are looking at will not control the expiration of other files that are not directly part of the response stream. With JS files why are you trying to expire them after 10 days anyway? The browser should recognize that they are no longer the current version and will download the latest, otherwise it will show a HTTP 304 Not Modified and will use the locally cached copy.

2
  • So why do the pagespeed suggests me to do that as you see in the second image? I think I'm not understanding the concept.
    – xkcd
    Nov 26, 2012 at 14:56
  • I would worry less about caching your JS files as most modern browsers do that anyway, instead you should look into minifying and consolidating your JS files which would provide more speed benefits over local caching. Nov 26, 2012 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .