Enabling Http caching and compression in IIS 7 for asp.net websites

Caching –

There are 2 ways to set Http caching

1-      Use Max age property

2-      Expires header.

Doing the changes via IIS Console –

1.       Select the website for which you want to enable caching and then select Http Responses in the features tab

 IIS 1

 IIS HEaders

 

2.       Select the Expires webcontent and on changing the After setting you can generate the max age property for the cache control

 Header DEtailed

 3.       Following is the screenshot of the headers

Response 

Then you can use some tool like fiddler and see 302 response coming from the server.

Doing it web.config way –

We can add static content section in the system.webserver section

<system.webServer>

  <staticContent>

            <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />

  </staticContent>

Compression -

By default static compression is enabled on IIS 7.0 but the only thing which falls under that category is CSS but this is not enough for most of the websites using lots of javascript.  If you just thought by enabling dynamic compression would fix this then you are wrong so please follow following steps –

 

In some machines the dynamic compression is not enabled and following are the steps to enable it –

  1. Open server manager
  2. Roles > Web Server (IIS)
  3. Role Services (scroll down) > Add Role Services
  4. Add desired role (Web Server > Performance > Dynamic Content Compression)
  5. Next, Install, Wait…Done!

 

  1.   Roles > Web Server (IIS)
  2.   Role Services (scroll down) > Add Role Services

 

 

  1. Add desired role (Web Server > Performance > Dynamic Content Compression)

 

 

  1. Next, Install, Wait…Done!

 

 

Enable  -

  1.   Open server manager
  2.   Roles > Web Server (IIS) > Internet Information Services (IIS) Manager

 

  1. Next pane: Sites > Default Web Site > Your Web Site
  2. Main pane: IIS > Compression

 

 

 

 

Then comes the custom configuration for encrypting javascript resources.

The problem is that the compression in IIS 7 completely works on the mime types and by default there is a mismatch in the mime types

  1. Go to following location

C:\Windows\System32\inetsrv\config

  1. Open applicationHost.config

The mimemap is as follows 

<mimeMap fileExtension=".js" mimeType="application/javascript" />

 

So the section in the staticTypes should be changed

 

       <add mimeType="application/javascript" enabled="true" />

 

 

Doing the web.config way –

 

We can add following section in the system.webserver section

<system.webServer>

<urlCompression doDynamicCompression="false"  doStaticCompression="true"/>

More Information/References –

·         http://weblogs.asp.net/owscott/archive/2009/02/22/iis-7-compression-good-bad-how-much.aspx

·         http://www.west-wind.com/weblog/posts/98538.aspx

 

Published Wednesday, December 29, 2010 5:20 AM by anil.kasalanati

Comments

# Twitter Trackbacks for Enabling Http caching and compression in IIS 7 for asp.net websites - Anil Kasalanati [asp.net] on Topsy.com

Pingback from  Twitter Trackbacks for                 Enabling Http caching and compression in IIS 7 for asp.net websites - Anil Kasalanati         [asp.net]        on Topsy.com

# re: Enabling Http caching and compression in IIS 7 for asp.net websites

Thursday, June 21, 2012 9:13 AM by Yirui

To create a virutal directory,  run your IIS Manager (I'm using IIS7.0):- In IIS Manager, expand the local computer(might be your PC's name) and Sites folder on the left hand side panel, and then find the web site that you want to add a virutal directory or you can right-click the  Sites  or folder where you want to create the virutal directory, and then click  Add Web Site  .

# re: Enabling Http caching and compression in IIS 7 for asp.net websites

Sunday, October 28, 2012 4:09 AM by HjbvlZzfhE

MLU3vY Thanks a lot for the article.Much thanks again. Great.

# re: Enabling Http caching and compression in IIS 7 for asp.net websites

Monday, November 05, 2012 12:38 AM by NbUTPbGREH

McHCZj Major thanks for the post.Much thanks again.

# re: Enabling Http caching and compression in IIS 7 for asp.net websites

Friday, February 01, 2013 7:51 PM by fOhNDTOLTryoTuq

atgmzL Hey, thanks for the blog article. Keep writing.

Leave a Comment

(required) 
(required) 
(optional)
(required)