Enabling Gzip Compression on IIS to Enhance Web Page Loading Speed
Benefits of Gzip Compression
Enabling Gzip compression significantly improves page load times. While code minification and image compression are beneficial, Gzip compression typically yields more substantial gains. It can achieve compression rates of around 70%, meaning a 30KB file can be reduced to approximately 9KB.
Step 1: Configure HTTP Compression in IIS
Open Internet Information Services (IIS) Manager. Right-click on you're website and select 'Properties'. Navigate to the 'Service' tab. Within the 'HTTP Compression' section, check the boxes for 'Compress application files' and 'Compress static files'. Configure the 'Temporary directory' and its size limit as needed.
Step 2: Enable the Web Service
Ensure the World Wide Web Publishing Service is runing.
Step 3: Modify the MetaBase.xml Configuration File
Open the directory C:\Windows\System32\inetsrv\. Locate the MetaBase.xml file and create a backup before editing. (Some server configurations may not require this step).
Search for the line containing Location ="/LM/W3SVC/Filters/Compression/gzip".
Review the existing compression scheme configurations. Replace the relevant sections with the following configuration to enable compression for common web file types:
<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/gzip"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="1"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="TRUE"
HcDynamicCompressionLevel="10"
HcFileExtensions="html
css
js
htm
xml
txt"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="php
dll"
>
</IIsCompressionScheme>
<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/deflate"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="2"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="TRUE"
HcDynamicCompressionLevel="10"
HcFileExtensions="html
css
js
htm
xml
txt"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="php
dll"
>
</IIsCompressionScheme>
After modifying the file, stop the 'IIS Admin Service' from the Windows Services console. Save the MetaBase.xml file and then restart the IIS Admin Service and the World Wide Web Publishing Service.
To verify successful Gzip compression, use an online tool to analyze your webstie's HTTP headers for the Content-Encoding: gzip response header.