1

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
Bargitta
  • 2,266
  • 4
  • 22
  • 35
  • Well, you're telling it to `GET` every time... server-side + client-side code doesn't relate to each other, hence the long AJAX and PHP Requests. – Nicholas Hazel Jan 24 '14 at 02:47
  • @NicholasHazel How can I set the server side or client side so that the css and javascript can be downloaded when they are modified? You see the cache-control:no-cache here, but I want it to be cached privately. – Bargitta Jan 26 '14 at 01:20
  • I'm really not sure. `server-side` code is not my specialty, and I can't imagine a way to do it `locally`. I'm sorry :-( – Nicholas Hazel Jan 26 '14 at 01:28
  • I find that though the cache-control in the response header says no cache, I will get a status code 304 when I download the page again,since the page is not modified and cached by the browser. – Bargitta Jan 26 '14 at 01:38

2 Answers2

1

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.

Shuping
  • 5,388
  • 6
  • 43
  • 66
  • agree, but just want to set the cache-control:public, so that intermediaries can also cache static files. – Bargitta Jun 12 '14 at 08:39
0

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>
Bargitta
  • 2,266
  • 4
  • 22
  • 35