Compressing Asp.Net Pages

Posted by Venkat | Labels: ,

Good Evening to All.
Here I am going to cover how to compress the .aspx pages.
so there are no.of ways to compress the pages in asp.net
1) using IIS.
2) using Code ie: through HTTPCompress.dll i got the source code from codeproject.com.
so i am going to share with you.
There are two type of Compression ie: Deflate , GZIP. here i am going to use GZIP compression to compress the asp.net pages.
First Place the DLL file ie::HTTPCompress.dll to the Bin folder of your project.
Then you have to include some tag on web.config file

<configsections>
  <sectiongroup name="Flanders">
   <section name="HttpCompress" type="Flanders.Library.Modules.HttpCompress.Configuration, HttpCompress">
  </section>
 </sectiongroup>
<flanders>
  <httpcompress compressiontype="GZip">
   <excludedpaths>
    <add path="NoCompression.aspx">
   </add>
   <excludedmimetypes>
    <add mime="image/jpeg">
   </add>
  </excludedmimetypes></excludedpaths>
</httpcompress>
</flanders>
</configsections>
Here i am using GZiP Compression technique. there are two more inner Tags ie: ExcludePaths, ExcludeMimeTypes.
ExcludePaths - It includes the Page Name that don't want to compress.
ExcludeMimeTypes - Include the mime types that dont want to compress the images..
By default images are compressed so no need to compress the image while using compression so our ExcludedMimeTypes tag should be like this.

<excludedmimetypes>
  <add mime="image/jpeg">
  <add mime="image/jpg">
  <add mime="image/png">
  <add mime="image/gif">
</add>
</add>
</add>
</add>
</excludedmimetypes>
Finally we need to add the httpModules

<httpmodules>
   <add> name="HttpCompressModule" type="Flanders.Library.Modules.HttpCompress.HttpModule,HttpCompress"/>
 </add>
</httpmodules>
Download Source Code

Credit goes to :
Ref: http://www.codeproject.com/KB/aspnet/HttpCompress.aspx

PayOffers.in