How to "Leverage Browser Caching" the right way?

Refell Jones asked on April 23, 2020 17:27

I am trying to improve the performance score of my Kentico Portal Engine website.

I added the web.config entries for the cachingControlMode and setup IIS to handle compressions and setting proper HTTP headers.

I still see some resources being served:

  • like the resources from App_Themes folder
  • GTM
  • Other links to css files created within Kentico

These still do not get cached.

Is there something else that needs to be done? Could people share their way of handling this?

Thanks.

Correct Answer

Dmitry Bastron answered on April 23, 2020 17:58

Hi Refell,

  • App_Themes files are just files on the file system so you should be able to use staticContent - clientCache settings in web.config. Do all of your files in App_Themes missing caching headers or particular file extensions/paths? Worth also checking in web.config that you enabled it for correct location as Kentico has 2 or 3 locations there by default.
  • GTM script caching is typically controlled by Google so you can't really do anything about it
  • If you are referring to the files from Kentico CMS than check these settings
1 votesVote for this answer Unmark Correct answer

Recent Answers


Refell Jones answered on April 24, 2020 08:29

Hi Dmitry,

Thanks for the helping me out on this.

I have web.config entry for the App_Themes folder. Yet the performance analysis tool lists some resources from the same folder, saying these are not being cached on the client side.

Do I need to do anything extra on top of this?

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on April 24, 2020 11:11

I'd rather check response headers for one of App_Themes files manually to see whether they contain cache-control header with max-age or expires header. Could you post here this part of your web.config related to App_Themes and actual response headers for one of those requests? It may be worth mentioning that sometimes those performance analytics tools are producing false-positive results. So it's better to check actual headers in the response.

Also, is it complaining about certain App_Themes files or specific only (i.e. fonts or css or anything else)?

0 votesVote for this answer Mark as a Correct answer

Refell Jones answered on April 24, 2020 11:21 (last edited on April 24, 2020 11:22)

Here is the block from web.config

<location path="App_Themes">
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="8.00:00:00" />
    </staticContent>
  </system.webServer>
 </location>

As per the report the caching is failing on

  • /CMSPages/GetResource.ashx?stylesheetfile=/App_Themes/projectname/css/custom.min.css (1 hour)
  • /App_Themes/Default/Images/favicon.ico (4 hours)

It could be a false positive as for the favicon I see the header set as cache-control: public, max-age=691200

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on April 24, 2020 11:39

Yes, looks like false-positive then. I've seen it with multiple scanners like WebPageTest. Have you tried in Google page speed insights or any other analyzer? Probably if you check in multiple and if all show the same result that would be strange indeed but will outline that there is a potential problem and it is actually positive.

0 votesVote for this answer Mark as a Correct answer

Refell Jones answered on April 24, 2020 11:42

I am using GTMetrix.

I will keep an eye on this issue.

Thanks for your help!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.