What is the best way to compress the Sitecore website? Do Sitecore provide any pipeline?
1 Answer
Assuming you want to serve compressed html to your visitors, the most popular method is gzip. Gzip compression is one of the standards of compression for the web; the other being deflate.
For a traditional Sitecore Asp.NET site (which Sitecore is built upon), the method to enable gzip compression is done by modifying your web.config and including something like below.
<system.webServer>
<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"/>
</system.webServer>
You may noticed that there are two types of compression: static and dynamic.
- Static compression compresses static content such as js, css, and images. Compression happens once. Subsequent requests will serve the already compressed files.
- Dynamic compression compresses for each request and the content is not cached to a file. This would be appropriate for Sitecore pages as content may be dynamic.
Note: Please consider the performance of the site before implementing "Dynamic Compression", it may lead to Performance degradation. Please visit the Analysis done in this Url https://www.webperformance.com/library/reports/iis7_compression/