Caching images for faster load time

Ashutosh Pandey asked on June 27, 2020 07:44

We are trying to improve load times for our website. I have following two questions:

This will allow caching of static content:

 <!-- 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="SiteName/media">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="8.00:00:00" />
      </staticContent>
    </system.webServer>
  </location> 

Q.1. The images uploaded to pages are stored and generated in SiteName/files directory on the root with auto generated folders and file names (snapshot attached). Should we also cache them? By adding entry like this:

  <!-- Generated images caching -->
  <location path="SiteName/files">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="8.00:00:00" />
      </staticContent>
    </system.webServer>
  </location> 

Q.2. Also in Settings -> System -> Performance, default value is 0 for Client cache (minutes): One of the blogs suggested the value should be 86400 which I think is 60 days (we can reduce that according to our updates). Just wanted to confirm if we should set some value to it like 7 days.

Screenshot

Recent Answers


Dmitry Bastron answered on June 29, 2020 10:47

Hi Ashutosh,

For Media Files (SiteName/media) and Attachments (SiteName/files) you don't need to add settings in your web.config. Typically it is enough to configure Settings -> System -> Performance -> Client cache (minutes), we usually set it to 1 year as existing images with the same URL are very unlikely to change. Also, have a look at the documentation article re client caching, it may give you more info.

1 votesVote for this answer Mark as a Correct answer

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