7
votes

In IIS 7.5 I have set the cacheControlMaxAge to be one year like so

<location path="Content/Images">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
      </staticContent>
    </system.webServer>
  </location>

As per this guide: Setting Expires and Cache-Control: max-age headers for static resources in ASP.NET

However, the Google PageSpeed tool is still saying that the files are not cached:

The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:
* https://local.example.com/Content/Images/image1.png (expiration not specified)
(etc)

Why does it say "expiration not specified"?

The entire webapp is served over https, is that a factor?

2
Have you inspected the http headers for image1.png? You can do this in your browser's dev tools (F12 in Chrome/FF/IE), under the network tab. Or you can use Fiddler. All modern browsers cache items over https if the max age is set.Giscard Biamby
The http headers say Cache-Control: public but no mention of expiry, what would the expiry header be called?JK.
Solved: adding the caching attributes to location path="Content" instead of location path="Content/Images" fixed the problem.JK.
Could you post the answer as an answer if you've solved the problem?Giles Roberts

2 Answers

5
votes

I solved this by changing the path specified from Content/Images to just Content

<location path="Content">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlCustom="public" 
                     cacheControlMode="UseMaxAge" 
                     cacheControlMaxAge="365.00:00:00" />
      </staticContent>
    </system.webServer>
  </location>

So it is fixed, but the changing of the path does not make it clear what the problem actually was.

0
votes

I've found Google PageSpeed in some instances takes a bit of time to 'catch up' with recent changes you've made. Make sure you've done a full page refresh and hit the refresh button in PageSpeed itself. Failing that, using Firebug on Firefox always seems to give accurate results in the net tab. Click the plus icon next to the file and examine the response headers.