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?

xkcd
  • 123
  • 5

2 Answers2

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

Greg Askew
  • 35,880
  • 5
  • 54
  • 82
  • 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 '12 at 15:10
  • 1
    I've verified that this does indeed work. Did you unlock the machine.config section? – Greg Askew Nov 26 '12 at 18:25
  • Ooh! I missed the unlocking part. You're right, it works like a charm! Thanks for your help. – xkcd Nov 27 '12 at 06: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.

Brent Pabst
  • 6,069
  • 2
  • 24
  • 36
  • 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 '12 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. – Brent Pabst Nov 26 '12 at 15:36