HTTP Compression with HttpCompress


This article is all about how to integrate HTTP compression to your web applications with the help of a free httpmodule named httpcompress. It assumes that you've already downloaded the module binaries from the authors site

Http compression is actually a performance optimization technique as documented in the HTTP1.1 protocol standard. It simply means that the Web Server will compress data, and send a compressed page to the browser, which the browser could decompress and display. This reduces the amount of data to be transferred from server to the client and so will speed up process. The speed increase is most noticable over slow connections.

The HttpCompress module is actually an httpmodule that can be plugged into your web application by editing the application configuration and it involves no recompilation of the entire project.

How to achieve it

The module we're going to use comes as two dll files

  • blowery.Web.HttpCompress.dll 
  • ICSharpCode.SharpZipLib.dll

After obtaining the files, please follow the steps below

  1. Place the files inside the 'bin' folder of your application.

  2. Open the application's configuration file, "web.config" and add the following entries to it.

  3. Locate the tag <configuration> , it is there in the starting you needn't require to search it out. Just below it add the segment.


    <sectionGroup name="blowery.web">

    <section name="httpCompress" type="blowery.Web.HttpCompress.SectionHandler, blowery.Web.HttpCompress"/>





    <httpCompress preferredAlgorithm="gzip" compressionLevel="high">


    <add type="image/jpeg"/>

    <add type="image/png"/>

    <add type="image/gif"/>



    <add path="NoCompress.aspx"/>




    This describes a new configSection named <blowery.web> and later this <blowery.web> section is configured. It contains a subsection <httpCompress> thet have to major attributes named
    , preferredAlgorithm and compressionLevel . preferredAlgorithm specifies which compression algorith is to be used and supported values are gzip/deflate/default. The compressionLevel attribute specifies the amount of comression and the possible values are high/normal/low

    The next section is excludedMimeTypes that specifies which MIME types are to be excluded from compression(You'll not benefit from compressing a jpg/gif image which is already compressed). You may add as many number of MIME types and they will not b compressed by HttpCompress while serving

    Then comes the excludedPaths section that allows you to exclude a specific path from being compressed.The example segment shows a page Nocompress.aspx being excluded.

  4. Plug-in the module into your application by adding the following lines just below the <system.web> section or anywhere inside it.


    <add name="CompressionModule" type="blowery.Web.HttpCompress.HttpModule, blowery.web.HttpCompress"/>


    This registers the http module with the application instance and it works as a filter for response to the client without directly sending the response to the client, HttpCompress compresses it and sends to the client.

NB:Its not necessary to use compression with your app by using an http module, if the hosted server already performs compression. Client browsers need to support compression for this to work as specified by "Accept-Encoding" in their request.