I've been taking a look, and implemented client caching on a development project I'm currently working on.
As I'm using Asp.Net, I've updated the web.config file directly with the following code:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
I've also implemented a 'fingerprinting' solution which allows me to expire CSS and Script files from the cache automatically.
However, I got to thinking what if an image changes - lets say it's modified and re-uploaded without being renamed. In this scenario I don't necessarily want the browser to continue caching the old version of an image for up to a year.
The question is therefore can a different cache duration be set for different file types using the web.config static content section?
A ClientCache instance controls the life cycle of the local singleton cache in a client.
IIS automatically caches static content (such as HTML pages, images, and style sheets), since these types of content do not change from request to request. IIS also detects changes to the files when you make updates, and IIS flushes the cache as needed.
You can use the location path to limit the cache to a folder or even down to a specific file. Not sure if you could do something like *.pdf
. Possible option here: Can I use wildcards in the web.config location path attribute?
<location path="images">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
</system.webServer>
</location>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With