Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web.Config - staticContent - clientCache configurations

Tags:

asp.net-mvc

I have this Content folder to hold js/images/css etc which doesn't change so often. So, I have added a config file to this directory which looks like this -

<configuration>
    <system.webServer>
        <staticContent>
            <!-- <clientCache cacheControlMode="UseExpires" httpExpires="Mon, 30 Nov 2015 20:45:45 GMT"/>  -->
            <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00"/>
        </staticContent>
    </system.webServer>
</configuration>    

When I load the page for the first time, I can see these response/request headers for a requested js file -

Response Headers
    Accept-Ranges:bytes
    Cache-Control:max-age=86400
    Content-Encoding:gzip
    Content-Length:1730
    Content-Type:application/x-javascript
    Date:Mon, 30 Nov 2015 12:14:31 GMT
    ETag:"038394f8fd11:0"
    Last-Modified:Mon, 26 Oct 2015 14:14:08 GMT
    Server:Microsoft-IIS/7.5
    Vary:Accept-Encoding
    X-Powered-By:ASP.NET
Request Headers
    Accept:*/*
    Accept-Encoding:gzip, deflate, sdch
    Accept-Language:en-US,en;q=0.8
    Cache-Control:no-cache
    Connection:keep-alive
    Host:dev.admin.ccmportal.williamslea.com
    Pragma:no-cache
    Referer:http://dev.admin.ccmportal.williamslea.com/
    User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36

Two questions -

  1. When I re-load the page using F5, I see same response headers with content length of 1730. Why content is reloaded even if I have set it to be cached for 1 day?
  2. What does Cache-Control:no-cache means in Request Header?

Thank you!

like image 499
inutan Avatar asked Dec 12 '25 20:12

inutan


1 Answers

  1. Content-Length will always show the content length, even when the content is pulled from cache.
  2. Cache-Control: no-cache tells the browser it SHOULD forward the request toward the origin server even if it has a cached copy of what is being requested.

Content-Length spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13

Cache-Control spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9

So it looks like your clientCache configuration is working correctly however it also looks like you're browser is not using the cache as per Cache-Control:no-cache

Do you have cache disabled in your dev tools or something similar?

like image 147
timothyclifford Avatar answered Dec 15 '25 16:12

timothyclifford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!