Leverage Browser Caching in Kentico for Improved Page Speed

5 MINUTE READ / BY LAURA FRESE

Page speed performance is of the utmost importance to us here at Refactored. Testing for page speed is part of our regular pre-launch checklist. One of the items that we look for to improve page speed is if things are properly cached. Kentico makes it easy to set up caching in the settings, however the client-side file caching settings only applies to dynamic files that are managed by the Kentico application. You will find that even after configuring these settings, Google PageSpeed Insights still says you need to leverage browser caching. In this post I will show how easy it is to add a few lines of code to the web.config to leverage browser caching in Kentico and ensure that physical files stored on the file system are properly cached, which will increase your google page speed score.

First, Make sure that Settings > System > Performance > Client Caching > Client Cache is set to 86400.

Then you will want to add the following blocks after the close of the system.web tag as shown below.

...  </compilation>  <httpCookies httpOnlyCookies="true" /> </system.web> <!-- app_themes caching --> <location path="App_Themes">  <system.webServer>    <staticContent>      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="8.00:00:00" />    </staticContent>  </system.webServer> </location> <!-- CMSScripts caching --> <location path="CMSScripts">   <system.webServer>     <staticContent>       <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="8.00:00:00" />     </staticContent>   </system.webServer>  </location>  <!-- Media Library caching -->  <location path="YourSiteName/media">    <system.webServer>      <staticContent>        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="8.00:00:00" />      </staticContent>    </system.webServer>  </location> 

It's that simple! Of course, this post assumes that you are storing media files on the file system and not in the database, and in the last block under "Media Library caching" you would change "YourSiteName" to whatever the root path is that the media library files are stored under. This trick can be used for any .NET site, not just a Kentico site, just change the location path to the location of your static files.


The Future of Kentico

Kentico 2020 - and the MVC model - are bringing big changes.

Kentico recommends upgrading now to MVC, to be ready for Kentico 2020. But is that big investment really necessary? Find out from our Kentico experts.

Download "The Future of Kentico" today.