Improve performance of static content like javascript, text, MS office documents(doc,xls,ppt), cs and html files in Windows Azure

Static compression is the feature that is shipped out of the box in IIS. Using static compression, developers/administrators can enable faster downloads of their web site static content like javascripts, text files, Microsoft office documents, html/htm files, cs files, etc. Below articles explain you in detail about compression in IIS

 

HTTP Compression <httpCompression>

https://www.iis.net/ConfigReference/system.webServer/httpCompression

URL Compression <urlCompression>

https://www.iis.net/ConfigReference/system.webServer/urlCompression

Configure Compression (IIS 7)

https://technet.microsoft.com/en-us/library/cc730629(WS.10).aspx

 

 

So, how can we make use of this feature when hosting the web application in Windows Azure? By default static compression is enabled in Windows Azure, however, there are only few mime types that will be compressed. Below is the default configuration in Windows Azure VM’s.

 

        <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" minFileSizeForComp="2700">

            <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="*/*" enabled="false" />

            </dynamicTypes>

            <staticTypes>

                <add mimeType="text/*" enabled="true" />

                <add mimeType="message/*" enabled="true" />

                <add mimeType="application/javascript" enabled="true" />

                <add mimeType="*/*" enabled="false" />

            </staticTypes>

        </httpCompression>

 

 

 

To customize static compression settings in Windows Azure, you can use startup tasks. Below are the steps I have followed to successfully enable static compression for few of the mime types my application needed.

 

 

1. Configure following tag in Application’s web.config @Configuration/System.WebServer

<urlCompression doStaticCompression``=”``true``”/>

2. Create iisconfigchanges.cmd file with required commands to customize ApplicationHost.config configuration of IIS

 

 

iisconfigchanges.cmd

 

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/x-javascript',enabled='True']" /commit:apphost

 

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='text/javascript',enabled='True']" /commit:apphost

 

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/vnd.openxmlformats-officedocument.wordprocessingml.document',enabled='True']" /commit:apphost

 

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',enabled='True']" /commit:apphost

 

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/vnd.openxmlformats-officedocument.presentationml.presentation',enabled='True']" /commit:apphost

 

%windir%\system32\inetsrv\appcmd.exe set config -section:serverruntime /frequentHitThreshold:1 /commit:APPHOST

 

exit /b 0

 

 

Above commands configures MIME types for javascripts, word documents (docx), Excel documents(xlsx), Powerpoint documents(pptx). If you need to compress any specific files other than mentioned above, find out the MIME types per your requirement and add similar commands to the file.

 

Note: I have changed frequentHitThreshold parameter since I could not see compression happening without explicitly specifying this parameter.

 

3. Add below startup task that will execute iisconfigchanges.cmd during startup of the rule. This configuration should be added in ServiceConfiguration.csdef under webrole/workerrole tag.

 

 

<Startup>

      <Task commandLine="iisconfigchanges.cmd" executionContext="elevated" taskType="simple" />

</Startup>

 

 

4. Addiisconfigchanges.cmd file to webrole/workerrole project

5. Configure below file properties for iisconfigchanges.cmd file , so that it will be copied to bin directory

 

Build Action : Content

Copy To Output Directory : Copy Always

 

Caution: Compression settings should be tweaked carefully, It might result in undesired performance too if not configured properly. For example, images like png are already compressed and compressing these types again, will cause additional CPU on the system without any significant gain in the bandwidth. I recommend you to research and thoroughly test your application with the compression settings before you apply the changes to production. I recommend below blog entry for further reading on IIS7 compression.

 

IIS 7 Compression. Good? Bad? How much?

https://weblogs.asp.net/owscott/archive/2009/02/22/iis-7-compression-good-bad-how-much.aspx