iiscachingbrowser-cachehttp-caching

How to configure cache on IIS 10?


I have a website and I have enabled caching as follows :

Screenshots :

enter image description here enter image description here enter image description here

When I browse my website, the first time it should load all the files, but if I refresh the page, files should be loaded from cache which is not the case (screenshot below). And in the response headers of the files I have :

cache-control: no-cache,max-age=2592000
content-encoding: gzip
content-length: 30116
content-type: application/javascript
date: Sun, 08 Mar 2020 04:31:20 GMT
etag: "80b55a25ef1d51:0"
last-modified: Tue, 03 Mar 2020 13:21:23 GMT
server: Microsoft-IIS/10.0
status: 200
vary: Accept-Encoding

Does anyone know how to solve that please ?

thanks Cheers,

enter image description here


Solution

  • It looks like you have enabled both clientcache and server side output caching at the same time. Based on your description, only client-side cache is required in this case.

    So please remove output caching rule from your IIS configuration.

    We just have to set <clientcache> section

    <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
    </staticContent>
    

    Cache-Control: max-age=86400

    Besides, please ensure your web browser has enabled client caching. Otherwise, static files will never be cached.

    Of course, failed request tracing will tell us how the cache control header generated.

    https://learn.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis