| |

How to enable dynamic GZIP compression on Azure Web App

Go to the Kudu on Azure

First should go to Kudu on Azure. Please visit https://docs.microsoft.com/en-us/azure/app-service/resources-kudu to get more insights.

You can just add “scm” to your azure web app URL as follows.

https://<yourapp>.scm.azurewebsites.net

Find CMD console

Then, you should navigate to the CMD console:

Find the application Config folder

Click on the “Site root” icon to see all folders listening as follows:

Find applicationhost.config file

Go to the config folder and find applicationhost.config file

As you can see, you have some essential options, including download, edit and remove next to each file.

Enable dynamic compression inside applicationhost.config

Modify applicationhost.config file by clicking on the edit icon.

Inside <system.webServer> tag, you should have the following compression settings:

  <urlCompression doStaticCompression="true" doDynamicCompression="true" />
  <httpCompression directory="C:\local\IIS Temporary Compressed Files" noCompressionForProxies="false">
      <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
      <dynamicTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/javascript" enabled="true" />
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/atom+xml" enabled="true" />
        <add mimeType="application/atom+xml;charset=utf-8" enabled="true" />
        <add mimeType="*/*" enabled="false" />
      </dynamicTypes>
      <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/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="image/svg+xml" enabled="true" />
        <add mimeType="*/*" enabled="false" />
      </staticTypes>
    </httpCompression>

Make sure your data type is included, and the app is restarted.

Compression is still not working?

You should monitor CPU utilization, RAM usage, and all essential performance metrics.

There is a chance that CPU utilization is too high and compression is disabled automatically through the default behavior described in the attached table.

dynamicCompressionDisableCpuUsageOptional uint attribute.
Specifies the percentage of CPU utilization at which dynamic compression will be disabled.
Note: This attribute acts as an upper CPU limit at which dynamic compression is turned off. When CPU utilization falls below the value specified in the dynamicCompressionEnableCpuUsage attribute, dynamic compression will be re-enabled.
The default value is 90.
dynamicCompressionEnableCpuUsageOptional uint attribute.
Specifies the percentage of CPU utilization below which dynamic compression will be enabled. The value must be between 0 and 100. Average CPU utilization is calculated every 30 seconds.
Note: This attribute acts as a lower CPU limit below which dynamic compression is turned on. When CPU utilization rises above the value specified in the dynamicCompressionDisableCpuUsage attribute, dynamic compression will be disabled.
The default value is 50.

Keep an eye on the above parameters & check httpCompression article to get more insights.

Big thanks to Wojciech Tengler for the valuable input.

Similar Posts