Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling gzip compression on Azure App Service

I have a web app hosted in microsoft azure. As local IIS uses compression for both static and dynamic content I expected this to work on azure platform as well. As it seems compression does not work as json and css files for example are returned uncompressed:

Request header

Response header

I have tried to set compression as mentioned in serveral posts (e.g. gzip compression in Windows Azure Websites or ) like this without any changes to the result:

<system.webServer>
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
  <httpCompression>
    <dynamicTypes>
    <clear />
    <add enabled="true" mimeType="text/*"/>
    <add enabled="true" mimeType="message/*"/>
    <add enabled="true" mimeType="application/x-javascript"/>
    <add enabled="true" mimeType="application/javascript"/>
    <add enabled="true" mimeType="application/json"/>
    <add enabled="false" mimeType="*/*"/>
    <add enabled="true" mimeType="application/atom+xml"/>
    <add enabled="true" mimeType="application/atom+xml;charset=utf-8"/>
  </dynamicTypes>
  <staticTypes>
    <clear />
    <add enabled="true" mimeType="text/*"/>
    <add enabled="true" mimeType="message/*"/>
    <add enabled="true" mimeType="application/javascript"/>
    <add enabled="true" mimeType="application/atom+xml"/>
    <add enabled="true" mimeType="application/xaml+xml"/>
    <add enabled="true" mimeType="application/json"/>
    <add enabled="false" mimeType="*/*"/>
  </staticTypes>
 </httpCompression>
[...]
</system.webServer>

As it seems the azure portal does not give me any option to change compression.

What do I need to do to enable compression or is it only possible when using a Vserver in azure?

like image 830
edesr Avatar asked Feb 16 '16 16:02

edesr


People also ask

How do I enable gzip in Apache?

To turn on Gzip compression, simply add on to the gzip directive in the main Nginx configuration file. $ sudo nano /etc/nginx/nginx. conf gzip on; Add file types to compress.

How do I enable gzip compression?

Gzip on Windows Servers (IIS Manager)Open up IIS Manager. Click on the site you want to enable compression for. Click on Compression (under IIS) Now Enable static compression and you are done!

How do you check gzip compression is enabled or not?

Double click on the file and select headers. Under 'Response headers' you are looking for the 'Connection-Encoding' field, it will say gzip if it is enabled.


1 Answers

You can change this in the web.config:

<system.webServer>
  <urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>

Then:

<httpCompression>
  <dynamicTypes>
    <clear />
    <add enabled="true"  mimeType="text/*"/>
    <add enabled="true"  mimeType="message/*"/>
    <add enabled="true"  mimeType="application/x-javascript"/>
    <add enabled="true"  mimeType="application/javascript"/>
    <add enabled="true"  mimeType="application/json"/>
    <add enabled="false" mimeType="*/*"/>
    <add enabled="true"  mimeType="application/atom+xml"/>
    <add enabled="true"  mimeType="application/atom+xml;charset=utf-8"/>
  </dynamicTypes>
  <staticTypes>
     <clear />
     <add enabled="true" mimeType="text/*"/>
     <add enabled="true" mimeType="message/*"/>
     <add enabled="true" mimeType="application/javascript"/>
     <add enabled="true" mimeType="application/atom+xml"/>
     <add enabled="true" mimeType="application/xaml+xml"/>
     <add enabled="true" mimeType="application/json"/>
     <add enabled="false" mimeType="*/*"/>
   </staticTypes>
 </httpCompression>

source: Microsoft forum

like image 185
Peter Avatar answered Sep 22 '22 08:09

Peter