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.
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.
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.
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...
Right click on your Web Sites folder, go to properties and open up the 'Service' tab and make it look like this...
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.
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.
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.
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.
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=220.127.116.11, "/>
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'!!
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.