1

I am trying to optimize image, js, and css delivery by enabling gzip compression and setting the client cache policy. The issue is, it doesn't seem like any of the settings are being used. Here is the settings I am trying to use

<caching>
  <profiles>
    <add extension=".js" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="21.00:00:00"/>
    <add extension=".css" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="21.00:00:00"/>
    <add extension=".png" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="21.00:00:00"/>
    <add extension=".svg" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="21.00:00:00"/>
    <add extension=".jpg" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="21.00:00:00"/>
  </profiles>
</caching>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
        staticCompressionDisableCpuUsage="95" staticCompressionEnableCpuUsage="60"
        dynamicCompressionDisableCpuUsage="95" dynamicCompressionEnableCpuUsage="50">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="image/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="*/*" enabled="false" />
    <add mimeType="application/json" enabled="true" />
    <add mimeType="application/json; charset=utf-8" enabled="true" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="image/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/atom+xml" enabled="true" />
    <add mimeType="application/xaml+xml" enabled="true" />
    <add mimeType="application/json" enabled="true" />
    <add mimeType="application/json; charset=utf-8" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>

Client Caching

I have specified 21 days caching for js, css, png, svg, and jpg. When I examine the headers for images stored in the Media Library the expires header is set to 7 days, and anything served from the file system has cache-control set to no-cache. Nothing I do changes this

Compression

CSS and JS files are being compressed, but png and svg files are not

What am I missing here? Are there Sitecore settings that might be interfering with IIS?

  • Are the png and svg files you are expecting to be compressed on the file system or media library? – Richard Seal May 9 '17 at 2:27
  • I guess it would make sense to manually compress any png on the file system since they would not be frequently updated. The media library images are what we need to automate since otherwise I would need to train all of the content editors how to compress images before uploading. – heilch May 9 '17 at 15:03
  • Read this article. You shouldn't compress files that are (or could be) natively compressed. So, don't compress you image files. – Josh Wheelock Mar 18 '19 at 11:46
2

To optimize images in the media library I recommend using Dianoga from the mind of @kamsar - it optimizes the image files after they are added into the media cache as an async process. So it doesn't affect the front end response times.

This can cause issues if you want to make sure images are cached on the client or if you are using a CDN, but you can change the async in to a synchronous call so that the CDN or browser will instantly get the optimized file. In those cases, you may want to consider a warm up script to prevent users from seeing the first hit delay as it processes the media.

| improve this answer | |
0

I had a partly related question myself a few days ago How to configure caching for static resources in Sitecore

It turned out that my problem was forgetting to do a hard-refresh (CTRL + SHIFT+R) in the browser!

BTW I found that the <caching>...</caching> section in web.config broke Sitecore completely.

| improve this answer | |
  • I have been using postman to check the headers, so there shouldn't be any client caching going on. And I'll try out that static caching reference and follow up with the results – heilch May 9 '17 at 14:44
  • @heilch I wouldn't assume anything. It only takes a minute to check if a hard refresh shows the changes, so I would try that at least. – Matthew Dresser May 10 '17 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.