Question

I develop an ASP.NET web application hosted in IIS 8.5 using https. I use fiddler to track the request and response, and find that css and js files are not cached by the browser (IE 11). For each page of the website, these files will be downloaded again. Here are the request and response. My question is why the reponse says "Cache-Control: no-cache", do I need to set anything in IIS?

GET https://***.com/Scripts/jquery-ui-1.8.20.js HTTP/1.1
Accept: application/javascript, */*;q=0.8
Referer: https://***.com/
Accept-Language: en-US
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: ***.com
Connection: Keep-Alive
Cookie: __AntiXsrfToken=000b8dfbde4b40a68a19a2ee3fc1195a; ASP.NET_SessionId=qdhotusxrcchnaowhagzol1y


HTTP/1.1 200 OK
Cache-Control: no-cache
Transfer-Encoding: chunked
Content-Type: application/javascript
Content-Encoding: gzip
Last-Modified: Tue, 16 Jul 2013 09:41:03 GMT
Accept-Ranges: bytes
ETag: "e74a9b96882ce1:0"
Vary: Accept-Encoding
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
X-UA-Compatible: IE=edge
Date: Fri, 24 Jan 2014 02:28:24 GMT
Was it helpful?

Solution 2

Set the cache for static files either in web.config or via UI in IIS, for the static file folder you want to cache, add this in the config file and it works.

<configuration>
    <system.webServer>
        <staticContent>
            <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1000.00:00:00" />
        </staticContent>
        <httpProtocol>
            <customHeaders>
                <add name="Cache-Control" value="public" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>
</configuration>

OTHER TIPS

From my understanding, Cache-Control: no-cache does not mean browser is not doing cache entirely but it tells browser to cache the content and browser should query if there is any change of the cached content by using Etag or Date headers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top