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

Posted by anil.kasalanati on ASP.net Weblogs See other posts from ASP.net Weblogs or by anil.kasalanati
Published on Wed, 29 Dec 2010 05:20:00 GMT Indexed on 2010/12/29 14:54 UTC
Read the original article Hit count: 787

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

 

© ASP.net Weblogs or respective owner

Related posts about c#

Related posts about IIS 7 caching compression dynamic static asp.net websites