6

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?

John Ohara
  • 2,821
  • 3
  • 28
  • 54

1 Answers1

2

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>
Community
  • 1
  • 1
Rick S
  • 6,476
  • 5
  • 29
  • 43