Up until now adding useful features to our ASP.NET IIS 6.0 hosted site has been the main driving force. Recently though, as our web site begins to take on a greater user load, performance, optimization, and scalability are becoming more of a focus for us.

I've had Firebug installed on FireFox3.0 for some time now, which is an essential tool if you are a web developer, or designer for that matter. I can't tell you how much easier it's made debugging javascript and and fiddling around with CSS.

Recently I installed YSlow which is a plugin for the Firebug plugin (vision: a chain of double adapter plugs) - it allows you to determine why your pages are slow (and they will be) and gives you some rules for speeding it up ... as defined by the Yahoo crew.

So I ran YSlow and this is the current state of play ... a big fat 'F' - FAIL! That simply won't do, so my goal over the next few weeks will be to get an 'A' grade.

image

The first item I thought I'd look at is Gzip components.

What is gzip? Basically it a file compression program that's supported by most browsers and web servers and allows you to serve up compressed http, therefore potentially making downloads a little faster. You can read all about it on wikipedia.

So how do you turn it on?

Well here's what I did for IIS 6.0. (When we switch to IIS7.0 I provide an update)

Well, as usual, search the internet and found these useful resources at MS TechNet, Coding Horror, and Scott Forsyth's Blog. Read all these and you'll be an IIS 6.0 Http Compression master! There are many scenarios and more advance things you can do but I'll list below the simple steps I took to get it working...

Step 1. Turn on Http compression in IIS 6.0

Right click on your Web Sites folder, go to properties and open up the 'Service' tab and make it look like this...

image

Step 2. Allow direct metabase edit

Next we'll go and edit the IIS metabase so if you don't want to shutdown IIS then right click on the IIS Server node, go to Properties and enable Metabase Edit.

image

I'm sure that there are security problems with leaving this switched on so switch it back off after you've done your edit in step 3. Easy.

Step 3. Edit the Metabase.xml

Open the C:\Windows\system32\inetsrv\metabase.xml file in notepad.

Find the IISCompressionScheme sections and change them to look like this...

<IIsCompressionScheme    Location ="/LM/W3SVC/Filters/Compression/deflate"

HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"

HcCreateFlags="0"

HcDoDynamicCompression="TRUE"

HcDoOnDemandCompression="TRUE"

HcDoStaticCompression="FALSE"

HcDynamicCompressionLevel="9"

HcFileExtensions="htm

html

txt

js

css"

HcOnDemandCompLevel="10"

HcPriority="1"

HcScriptFileExtensions="asp

dll

exe

aspx

asmx"

>

</IIsCompressionScheme>

<IIsCompressionScheme    Location ="/LM/W3SVC/Filters/Compression/gzip"

HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"

HcCreateFlags="1"

HcDoDynamicCompression="TRUE"

HcDoOnDemandCompression="TRUE"

HcDoStaticCompression="TRUE"

HcDynamicCompressionLevel="9"

HcFileExtensions="htm

html

txt

js

css"

HcOnDemandCompLevel="10"

HcPriority="1"

HcScriptFileExtensions="asp

dll

exe

aspx

asmx"

>

</IIsCompressionScheme>

Obviously there are a few things to try in here (read the resource links above for more info) but all I did was change the HcFileExtensions, HcScriptFileExtensions, and the HcDynamicCompressionLevel.

Note: There are alternatives to editing this file directly like using the Adsutil.vbs, I tried some of the suggestions but it wasn't working for me initially (i'm sure it was something simple), so I moved on to editing the file directly ... much easier.

Step 4. Reset IIS

Now checking my YSlow results again and, ... only get a 'B' grade! WTF! Apparently this is because we're using MS ASP.NET AJAX and the WebResource.axd won't compress, hmm I did some searching and found that there were a few options available to me, so I checked out MbCompression on CodePlex.

Step. 5 Compress WebResource.axd

Do this by following his instructions here.

(UPDATE: The correct instructions can be found in the source code download from CodePlex)

Unfortunately though he indicates the wrong namespace to use (Miron.Web.HandlersAndModules) ... so with the help of Reflector I found the correct namespace (Miron.Web.MbCompression). To get the basic compression happening modify your web.config ... it should look something like below ...

<httpModules>

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule,

System.Web.Extensions, Version=3.5.0.0, "/>

<add name="PageCompressionModule"

type="Miron.Web.MbCompression.PageCompressionModule"/>

<add name="WebResourceCompressionModule"

type="Miron.Web.MbCompression.WebResourceCompressionModule"/>

</httpModules>

Now, run YSlow again ... overall Performance Grade of 'D' (60) ... which is not great, but better than a fail. And now if you check out the Gzip components ... grade 'A'!!

image

The MbCompression seems to have a few more tricks up it's sleeve which I will try to use to minify js and css.

Next Time : Minify JS, Put JS at the bottom, and Put CSS at the top.

Gzipcom_8E95/image_2.png

/IIS/502ef631-3695-4616-b268-cbe7cf1351ce.mspx?mfr=true

sGzipcom_8E95/image_8.png

sGzipcom_8E95/image_6.png

Implementation.aspx

sGzipcom_8E95/image_4.png

Comments

Comment