HTTP Compression

I serve my website off of my home computer which has a decent broadband connection. The upload speed however is a mere 384KB, which used to make my web pages slow in loading up until I enabled HTTP compression and let me tell you it is a real blessing. Not only does it save a lot of bandwidth, but more importantly my pages are a lot more responsive.

Most modern browsers support two compression algorithms, GZip and Deflate. I am using Blowery an open source compression software for serving my web pages in Deflate compression mode. The other thing I enabled last week on my site was AJAX using the new Microsoft Atlas Framework. What I saw was that one of the JavaScript files served to the browser was a whopping 242KB. Although script files get cached by the browser, the speed on the first serving on my web page would be aweful.

The Javascript files are served through a new concept in ASP.NET called Web Resources, where you can embed JavaScript and image files directly into your assembly as resources. When the ASP.NET engine gets a request for these resources it extracts these files out of the assembly and serves them. The file that does is called WebResource.axd. I don't have a clue as to what that file is / does, but I will do some reasearch to find out. The point is that by enabling Blowery the JavaScripts on my web pages stop working. I found a patch for this. You have to add the following lines to the httpCompress section required by blowery in the web.config

<excludedPaths> 
      <add path="ebresource.axd"/>
      <add path="webresource.axd"/> 
</excludedPaths>

Having fixed the web pages, I still wanted to do something about those huge Atlas files. Luckily some smart Atlas developers at Microsoft have coded a compression routine for the resource files that are served through webresource.axd. You can enable it by adding the following line in the httpModules section to your web.config.

<httpModules>
      <add name="WebResourceCompression"
           type="Microsoft.Web.Services.WebResourceCompressionModule" />
</httpModules>

An important point to note is that this needs to be above the blowery http module. That is blowery also is an httpModule that needs to be added to the httpModules section in the web.config. However by keeping the add tag for blowery above the atlas module, my Atlas JavaScripts were not getting compressed. Moving the tag fixed the problem.

Have fun!


No Responses

Leave a Reply

Please enter all required information

*

*

*