Iis CSS Caching

IIS CSS Caching

If you're serving your CSS from static files (or anything that the query string doesn't matter for), try varying that to ensure that the browser makes a fresh request, as it will think that it's pulling a completley different resource, so have for example:

"styles.css?token=1234" in the CSS reference in your markup and change the value of "token" on each CSS check-in

Caching specific Javascript and CSS files

You can configure IIS to cache specific files by extension. For example:

Select the folder where your css/js files reside and then click on Output Caching.
Sample Image

Then add the file extensions that you want to cache:

Sample Image

I don't think you can specify which ones to cache on a per file basis unless you write an http handler module to add the appropriate headers for each file independently, but from IIS this is how is done.

Then you can verify that you are getting 304 responses using firebug / fiddler or your tool of choice.

I hope this is helpful.

Chrome will not cache CSS files. .js files work fine

I faced similar kind of issue and turns out to be web.config's compilation attribute was set to debug=true, as-

<compilation debug="true"></compilation>

It causes your files to neither be bundled nor cached on browser. Just removing debug=true resolved my issue. So I changed it to-

<compilation></compilation>

Edit-

For Chrome specifically, it could be related to your certificate.

Chrome does not cache resources from servers with self-signed certificate.

See here

How to configure cache on IIS 10?

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



Related Topics



Leave a reply



Submit