Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS 7.5 adds no-cache to cache-control response

I'm using Azure and IIS 7.5 to serve my web app, I'm not using .NET though.

I'm trying to override the default cache-control value for my static files but it seems that IIS 7.5 adds no-cache no matter what I specify.

My approot/web.config file looks like this:

<?xml version="1.0"?>
<configuration>
  <system.webServer>
    ...

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

  </system.webServer>
</configuration>

and my response headers are:

Accept-Ranges:bytes
Access-Control-Allow-Origin:*
Cache-Control:no-cache,public,max-age=2592000
Content-Encoding:gzip
Content-Length:4309
Content-Type:application/x-javascript
Date:Mon, 10 Sep 2012 14:42:07 GMT
ETag:"8ccd2f95a8fcd1:0"
Last-Modified:Mon, 10 Sep 2012 13:48:36 GMT
Server:Microsoft-IIS/7.5
Vary:Accept-Encoding
X-Powered-By:ASP.NET

I do have an extra web.config file in one of the subfolders but that doesn't override any clientCache values.

Does anyone know why IIS is prepending no-cache?

Thanks!

like image 539
Marco Fucci Avatar asked Sep 10 '12 15:09

Marco Fucci


People also ask

What happens if there is no-cache-control header?

Regarding "Without the cache control header the browser requests the resource every time it loads a new(?) page", that doesn't seem to be the case with Google Chrome. It seems to cache those items indefinitely.

What is incomplete or no-cache-control header set?

The cache-control header has not been set properly or is missing, allowing the browser and proxies to cache content.


1 Answers

Apparently, the output cache needs a location attribute otherwise it will override the staticContent/clientCache setting.

<system.webServer>
    ...
    <caching>
        <profiles>
            <add extension="*" policy="CacheForTimePeriod" duration="00:01:00" varyByQueryString="*" varyByHeaders="X-Requested-With" location="Any" />
        </profiles>
    </caching>
    ...
</system.webServer>
like image 57
Marco Fucci Avatar answered Oct 01 '22 13:10

Marco Fucci