Quicktip: Set Client Cache for Specific Static Files on .NET

Many security and performance evaluation tools are going to call out that static files need to have the proper cache settings in their response headers. In short, this informs the client browser whether and how long it should keep a file before requesting it again for the server.

We may not want to apply a blanket cache policy on all static files since that could impact CMS performance. However, we normally isolate our client-specific files in an “assets” or “Content” directory which we can use to be more selective.

Include this snippet within the “configuration” node of your Web.config

<location path="assets">
      <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />

For files that change between deployments (compiled CSS, JS), you will want to continue using some kind of date- or hash-based “cache bust” key.

Leave a Reply