Enable Gzip in Asp.Net Application

When it comes to optimizing the web there are many options available.  I have talked about several of them before like image compression, using sprites, CDN’s, etc.  Today I am going to talk about another option which is called GZIP.  The idea is simple.  If you have a file on a server and want to send it to a local computer then most of the time it is faster to have the server compress the file, send it and then have the local machine uncompress it.  However; in order to get this to work you need to tell the local computer that you are sending a compressed response.  Since all current browsers can handle this type of compression it makes it sense to enable this on your site.

Also another issue that has been removed since asp.net 4.0 is that enabling this on the server usually meant that you had to have admin rights to the server in order to configure IIS to handle this. This is no longer the case when it comes to using GZIP on a .NET 4.0 application.  You can now add it to the <system.webServer> node under the web.config file.

<!--Runs Gzip-->
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/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>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>

This is just an example of what the web.config might look like. To better understand what types of files should be under dynamicTypes vs. StaticTypes please read the following short explanation from http://www.iis.net/configreference/system.webserver/httpcompression

•Static Compression:
You should use static compression with files that do not typically change, such as HTML files (*.html, *.htm), text files (*.txt), Microsoft Office documents (*.doc, *.xls, *.ppt), etc. The size of these files can be reduced through compression, which reduces download times for client requests and reduces bandwidth on the server.

Note: Image files such as *.png and *.png files are also static files, but typically they do not benefit from HTTP compression because these image files are already compressed.

•Dynamic Compression:
Unlike static compression, IIS 7 performs dynamic compression each time a client requests the content, but the compressed version is not cached to disk. This change is made because of the primary difference between static and dynamic content. Static content does not change. However, dynamic content is typically content that is created by an application and therefore changes often, such as Active Server Pages (ASP) or ASP.NET content. Since dynamic content should change often, IIS 7 does not cache it.

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , | Posted under ASP .NET 4.0, Programming/Coding | RSS 2.0

Author Spotlight

David Bauernschmidt

David Bauernschmidt

I live in the historical triangle of Virginia where I am married with two daughters. I have spent over 13 years working for a Fortune 500 company in the computer area. I started in VB 6.0 and by the time I ended my employment I was supervising a development team where we built many web applications. When my first daughter was born I wanted to spend more time with her so I left and became a programmer analyst for local government as well as launch my own company. Since then I have grown James River Webs into a profitable web design and application company helping small businesses create a big presence on the internet. As an employee I have created web application used by citizens and other companies. I enjoy fly fishing, and spending time with my family. I also enjoy learning new approaches and development tools when it comes to developing applications.

Leave a Reply

Your email address will not be published. Required fields are marked *


4 + 3 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>