What is HTTP compression?

Text files transferred by HTTP such as css, html, javascript etc are highly compressible – by their nature they can be compressed to a fraction of their original size quickly without much webserver CPU load.

IIS can perform this compression on your original uncompressed css/html/javascript source files and transfer the compressed content to people’s web browsers. Their browsers then expand the compressed files whilst browsing saving a great deal of bandwidth/download time. Important to note is that the people browsing are never aware that they’re browsing a compressed website.

Should I bother?

Brightminds.co.uk homepage download size shrank from 660KB to less than 400KB. This saving however includes image downloads and the real compression saving takes the page weight from 77KB down to only 12KB. Thus less than a sixth of the page size is downloaded by a browser at a tiny CPU load cost. End result? Since expanding the page on the user’s browser requires practically no CPU load, everyone’s browsing experience is significantly faster. But what about the webserver CPU cost? It’s far smaller than the CPU cost of uploading a further 64KB to the user.

The Bottom Line – HTTP compression is free and quick to enable. If you’re not using HTTP compression, you’re compromising your reader’s/customer’s experience and burning bandwidth.

Lets enable it!…

There’s a great deal of conflicting articles on the web about how to enable compression correctly in IIS6. Some say that you will need to edit the metabase whilst others say a simple cscript will do all. I’ve found you’ll need to do both and I’ll outline how below…

Make a backup of your existing IIS6 configuration by opening Computer Management, expanding IIS and then right clicking on it to All tasks – Backup/restore configuration.

Backing up IIS configuration

Backing up IIS configuration

Click on Web Service Extensions within IIS, right click and select to add a new web service or extension. Call it HTTP Compression and add %systemroot%\System32\inetsrv\gzip.dll as a required file. Select to allow the extension and click OK.

New IIS Service or Extension

New IIS Service or Extension

Within IIS right click on ‘Websites’ and go to Properties. Click on the Service tab and tick the box to ‘Compress application files’ (this will compress files sent with the extensions .asp, .aspx etc) and also tick the box to ‘Compress static files’ (compressing .html, .css etc).

Enabling Compression in IIS6

Enabling Compression in IIS6

If you want to specify a different directory to store the temporary files to then do. Specify a storage limit, although brightminds.co.uk have up to 250,000 compressible hits a day I’ve never seen the compression directory exceed a few MB. 1GB will be more than enough. Click OK.

Now we need to specify which file types are compressed by IIS. Individually copy, paste and run the following commands into the Run box.

cscript c:\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/Filters/Compression/deflate/HcFileExtensions htm html txt css js
cscript c:\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/Filters/Compression/gzip/HcFileExtensions htm html txt css js
cscript c:\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/Filters/Compression/deflate/HcScriptFileExtensions asp dll exe aspx asmx php
cscript c:\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/Filters/Compression/gzip/HcScriptFileExtensions asp dll exe aspx asmx php

These commands enable the compression formats deflate and gzip for the specified file types. So for example the last command enables gzip compression for files with the extensions .asp, .dll, .exe, .aspx, .asmx and .php. You may ask why not compress .jpg image types and indeed all web content. Simple answer – text files compress quickly and exceedingly well, images/videos etc don’t.

Right click on IIS again in Computer Management and stop all IIS services.

Now Run the following command from the Run box to edit the IIS Metabase…

Notepad %systemroot%\system32\inetserv\metabase.xml
Editing the IIS Metabase

Editing the IIS Metabase

Find/search for the line that contains the following tag – ‘<IIsCompressionScheme’. There should be two of them, one referring to gzip and another for deflate (the two compression methods). HcFileExtensions should state the static file extensions we want to compress – htm, html, txt, css and js. Likewise HcScriptFileExtensions should state the dynamic file extensions to be compressed – asp, dll, exe, aspx, asmx and php.

What we need to do is edit HcDynamicCompressionLevel=”0″ for both gzip and deflate to be HcDynamicCompressionLevel=”9″. This defines the compression level on a scale between 0 and 10. 0 doesn’t compress and 10 uses far too much CPU load compressing, 9 is generally the best option.

Double check you have changed HcDynamicCompressionLevel for both gzip and deflate and save the file changes (File > Save).

Again in Computer Management Right click on IIS Computer Management and start all IIS services.

Your IIS web server should now be serving a compressed website. Double check it by entering your domain into http://www.whatsmyip.org/http_compression/.

  • Share/Bookmark
footballshirts

Googleing 'Football Shirts'

Google the highly competitive search term ‘Football Shirts’ and consider the result.

The all important first result highlights the search term in all three result return areas – the title, description and URL. To climb to the coveted number one position all too often you’ll need an appropriately keyworded title, description and URL.

Including your most important keywords into your page’s Title and description is easy – just change the <title> and <meta name=”description”> tags however changing the URL structure is an altogether different ball game – especially in ASP.

Fundamentally we want to design a heirarchy of pseudo keyword-rich URLs. When a user browses your website these pseudo URLs are then remapped to real URLs. For example party-packs.co.uk have a product page URL…

http://www.partypacks.co.uk/gold-and-black-celebration-disposable-camera-pid72318.html

The likely real URL is something like…

http://www.partypacks.co.uk/part.php?part=72318

And so a remapping function could be visualised as…

http://www.partypacks.co.uk/<product-title>-<part-code>.htm
…mapped to…
http://www.partypacks.co.uk/part.php?part=<part-code>

If your webserver runs UNIX this can be performed using the mod_rewrite feature built into APACHE web server. See here for a very easily understood integration article. Here however we’re talking about ASP, so I’ll get more to the point.

The ASP scripting language is hosted on Microsoft’s IIS webserver and has its own URL rewriting engine which, although free, is needlessly complicated and poorly documented/used online. Take my advice and avoid it, look at one of my favourite software tools – HeliconTech ISAPI ReWrite.

ISAPI ReWrite simply emulates APACHE’s mod_rewrite and all its advantages. It’s flexible, fast and very well documented online. If you’re happy to go for the ‘lite’ version (whose only limitation is it can only host one website per webserver) it’s even free! There’s even someone on their support forum called Anton, a hero amongst men that answers all the support tickets within mear hours with straightforward answers. So, to its installation/integration and some examples…

Download the x86/x64 MSI and install it on your webserver. Start the software and select to edit the config file. This is basically a txt file that controls the remapping configuration. Here is where you declare your URL mapping rules.

Taking brightminds.co.uk as an example, they have a generic part page whose real location is the following…

http://www.brightminds.co.uk/showPart.asp?part=A001

…where A001 is the part code of the part being viewed. If A001 were called ‘Soft Dog Toy‘ and found in the keyword-rich category/sub-category heirarchy play-toys/animals then the full desired pseudo URL would be…

http://www.brightminds.co.uk/play-toys/animals/soft-dog-toy.htm

Important – Use hyphens rather than underscores for keyword separation. Underscores are not interpreted correctly by Google.

The mapping function desired would therefore look something like…

http://www.brightminds.co.uk/<category>/<subcategory>/<part-title>.htm

Since there’s a generic part page, we can ignore the <category> and <subcategory> for this rewrite rule as they don’t need to be taken into account. Thus what we’re left with is the need to query a database for the <part-code> in response to the <part-title>.

ISAPI ReWrite has no database API so you need to create mapfiles. Mapfiles are simple txt files that map simulated queries so for this example we would need the following mapfile, saved as mapfile.txt…

soft-dog-toy     A001
another-description     A002

Important – The file needs to be TAB delimited with each line separated by a formal line break.

Now all we need is the mapping rule. Begin the config file with the initialisation and then the rule.

RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:mapfile.txt
RewriteRule ^([^?/]+)/([^?/]+)/(^?/+)\.htm /showPart.asp?part=${mapfile:$3}

Line 3 is fairly self explainatory – declare the mapfile as ‘mapfile’. Subsequent mapfiles can be declared as…

mapfile2 txt:mapfile2.txt

Be aware that by declaring mapfile2.txt you’re doing just that i.e. file declarations, unless otherwise stated are treated as the www root. It is wise to use secure locations such as C:\mapfiles etc, something not accessed by IIS.

Line 4 is where the funky things happen. It’s formatted as the following…

Rewrite Rule <pattern-to-find> <pattern-to-apply> <options>

Each ([^?/]+) means a variable that can be used in the rule. The rule looks at the 3rd variable in the URL pattern (the part title) and via the mapfile finds the part code. The part code is then used in the real URL. Hence, what’s shown as the keyword-rich pseudo URL to users, spiders etc now maps to the real URL.

  • Share/Bookmark