14

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?

Community
  • 1
  • 1
edesr
  • 200
  • 1
  • 1
  • 12

1 Answers1

13

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

imgen
  • 2,803
  • 7
  • 44
  • 64
Peter
  • 27,590
  • 8
  • 64
  • 84
  • Hi Peter, I changed the web.config (updated my post) with the sample you provided. I checked the result and compression isn't working. Is it correct to add the httpCompression tag inside the system.webServer tag? – edesr Feb 17 '16 at 16:39
  • 1
    The above information is correct, however it doesn't work for me either, did you ever get it to work? – Darren Jun 05 '16 at 00:47
  • I believe this above is for Websites only – Old fart Jun 09 '16 at 17:07
  • 5
    I had the same issue on an Azure Web App using the same configuration like yours but it seemed not to work. I left it for some time refreshed the page at it worked. I guess it might have been some caching issue somewhere. Also I removed the application/json mime type from the statictypes section. I don't want the server serving me a cached version because most often they are results of controller actions fetched from a database. You can check this link for more information https://www.iis.net/configreference/system.webserver/httpcompression – code-assassin Jun 22 '17 at 10:23
  • I have the same issue no solution in sight. – Pablo Jomer Sep 21 '17 at 08:23
  • @code-assassin I am having the same issue with my website on Azure. Any additional advise other than what you already said? – Lyubomir Ivanov Valchev May 24 '20 at 11:24
  • @LyubomirIvanovValchev I think that you should check this out: https://piotrbach.com/enabling-dynamic-gzip-compression-azure-web-app/ – wtct Jul 21 '22 at 11:21