Loading...
Area: Episerver CMS
Applies to versions: 10 and higher
Other versions:

Configuring caching of files

You can add cache information to the response headers at request of static files so the client can cache files and not have the web server serve at each request, significantly reducing the total request time for a client.

You can set the staticFile section of web.config on a location level. For the <staticFile> section to be available, you have to add it to <configSections> first:

<section name="staticFile" type="EPiServer.Framework.Configuration.StaticFileSection, EPiServer.Framework.AspNet" allowLocation="true" />

This staticFile section controls the Expires and Cache-Control cache header directives. You can set different expiration times depending on the path to the static file. The staticFile configuration is used by both the StaticFileHandler that delivers files from Virtual Path Providers and by the media system in CMS. Files delivered by IIS, such as CSS and other resources on the website, are configured using standard IIS configuration settings.

<configuration>

<!--Configures expiration for files in CMS/VPP-->
<staticFile expirationTime="12:0:0" />

<!--Configures expiration in IIS-->
<system.webServer>
   <!--Configures client headers for static files from IIS-->
   <staticContent>
       <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00"></clientCache>
   </staticContent>
   <!--Configures output and kernel caching for ALL images (both CMS and IIS)-->
   <caching>
      <profiles>
        <add extension=".gif" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".js" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".jpeg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
      </profiles>
   </caching>
</system.webServer>
</configuration>
Do you find this information helpful? Please log in to provide feedback.

Last updated: Feb 17, 2020