<p>On a normal Windows IIS installation it's pretty easy to turn on dynamic compression for WFC and other served content to reduce the amount of bandwidth you need to consume (important when you are charged by the byte) &ndash; you just change the server properties to enable dynamic as well as the more common static compression.</p> <p></p> <p>With Windows Azure though it's a little more interesting because with roles dynamically assigned and started from a standard instance you don't have much control &hellip; unless you're used to doing everything from the command line &hellip;</p> <p></p> <p>Luckily one of the nice things that you can do with an Azure role is script actions to take place as part of the initialization. The process is as simple as adding the commands you need to execute to a batch script that gets deployed as part of your project and calling it at the relevant time.</p> <p></p> <p>The first thing you script needs to do is to turn dynamic compression on for the server in that role:</p> <p class="MsoListParagraph"> <span style="font-size:10pt;line-height:125%;font-family:Symbol;"><span>&middot;<span style="font:7pt Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size:10pt;line-height:125%;font-family:Courier New;">"%SystemDrive%WindowsSystem32inetsrvappcmd.exe" set config -section:urlCompression /doDynamicCompression:true /commit:apphost</span></p> <p></p> <p>You then want to set the minimum size for files to be compressed (in bytes)</p> <p class="MsoListParagraph"> <span style="font-size:10pt;line-height:125%;font-family:Symbol;"><span>&middot;<span style="font:7pt Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size:10pt;line-height:125%;font-family:Courier New;">"%SystemDrive%WindowsSystem32inetsrvappcmd.exe" set config -section:system.webServer/httpCompression -minFileSizeForComp:50 /commit:apphost</span></p> <p></p> <p>Finally your script should specify the MIME types that you want to enable compression for</p> <p class="MsoListParagraph"> <span style="font-size:10pt;line-height:125%;font-family:Symbol;"><span>&middot;<span style="font:7pt Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size:10pt;line-height:125%;font-family:Courier New;">"%SystemDrive%WindowsSystem32inetsrvappcmd.exe" set config /section:httpCompression /+dynamicTypes.[mimeType='application/xml',enabled='true'] /commit:apphost</span></p> <p class="MsoListParagraph"> <span style="font-size:10pt;line-height:125%;font-family:Symbol;"><span>&middot;<span style="font:7pt Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size:10pt;line-height:125%;font-family:Courier New;">"%SystemDrive%WindowsSystem32inetsrvappcmd.exe" set config /section:httpCompression /+dynamicTypes.[mimeType='application/atom+xml',enabled='true'] /commit:apphost</span></p> <p class="MsoListParagraph"> <span style="font-size:10pt;line-height:125%;font-family:Symbol;"><span>&middot;<span style="font:7pt Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size:10pt;line-height:125%;font-family:Courier New;">"%SystemDrive%WindowsSystem32inetsrvappcmd.exe" set config /section:httpCompression /+dynamicTypes.[mimeType='application/json',enabled='true'] /commit:apphost</span></p> <p></p> <p>If you have a problem with MIME types like atom+xml not registering properly you may need to escape the plus sign and replace the string with 'atom%u002bxml' &ndash; I've had success with both methods</p> <p></p> <p>You can add as many MIME types as you need to the list, and remember that sometimes you also need to specify the characterset you are using</p> <p class="MsoListParagraph"> <span style="font-size:10pt;line-height:125%;font-family:Symbol;"><span>&middot;<span style="font:7pt Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size:10pt;line-height:125%;font-family:Courier New;">"%SystemDrive%WindowsSystem32inetsrvappcmd.exe" set config /section:httpCompression /+dynamicTypes.[mimeType='application/xml;charset=utf-8',enabled='true'] /commit:apphost</span></p> <p></p> <p>And then when you're done exit the script to tidy up gracefully</p> <p class="MsoListParagraph"> <span style="font-size:10pt;line-height:125%;font-family:Symbol;"><span>&middot;<span style="font:7pt Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size:10pt;line-height:125%;font-family:Courier New;">exit /b 0</span></p> <p></p> <p>Once you have combined those steps together in a script and saved it as (eg) EnableDynamicCompression.cmd you should add the script to your Visual Studio project and make sure you select "Copy Always" in the properties for the file to ensure it gets correctly deployed.</p> <p></p> <p>Finally you need to add a reference to that startup script in your project's ServiceDefinition.csdef file and then deploy your project as normal.</p> <p></p> <p style="margin-bottom:7.5pt;line-height:125%;"> <span style="font-size:10pt;line-height:125%;font-family:Courier New;">&nbsp;&nbsp;&nbsp; &lt;Startup&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Task commandLine="EnableDynamicCompression.cmd" executionContext="elevated" taskType="simple"&gt;&lt;/Task&gt;<br /> &nbsp;&nbsp;&nbsp; &lt;/Startup&gt;</span></p> <p>Finally&hellip; how do you know if it's working or not? The thing that tricks people a lot of the time and makes them think it's broken is that if they are behind a corporate proxy server that often un-compresses the data for you on the way past. You can check yourself using a tool like <a href="http://fiddlertool.com/">Fiddler</a> to examine the response and make sure it has been gzipped or you can visit <a href="http://www.whatsmyip.org/http_compression/">http://www.whatsmyip.org/http_compression/</a> and test that way (the latter is good if you are behind a proxy which interferes with the compression).</p>