Increasing Website Performance

As developers, we often spend most of our time planning a database strategy, optimizing algorithms, etc., when it comes to tweaking performance of an application.  It makes sense, because that's where the true architectural decisions are made.  HTML and Javacript (not counting AJAX) seldom fall on the developer's plate for performance tuning (usually, that's fine by them).  Let's face it:  there's nothing glorified about tweaking HTML tags and finding that perfect balance of image quality vs. size.   *Yawn* That was fun in '95 (and even then only for a few weeks).

Still, though, there's quite a bit that can be done on the front end to help boost performance.  If the application is large enough, a content distribution network (like Akamai) is a good choice.  But for smaller apps -- even intranet apps -- there's a couple of tweaks we can make, namely: compression and content expiration.

Compression typically uses gzip or deflate algorithms to create a lossless, smaller version for transmission.  Since clients should support this transparently (their the ones who send the Accept header, so they should be able to handle it) it's a pretty easy implementation.  If client's don't accept the encodings you're offering -- such as gzip or deflate -- no worries, IIS sends the plain text version.

The problem with compression is that it doesn't work well on dynamic pages.  With static content, IIS will cache the file until it is modified, reducing the processing overhead on the server.  If dynamic caching is used, each request is compressed on the fly, resulting in a larger CPU overhead that may not be worth the hassle (unless you're sending really big pages and have the CPU cycles to spare).  To boot, Javascript files (*.js) are not enabled for static compression by default.  (I think this had something to do with some earlier browser incompatibility issues.)   Enabling compression on ASPX and JS files requires some metabase editing, so if you're up for the challenge, here's a good starting point:
http://www.dotnetdevs.com/articles/IIS6compression.aspx

Aside from compression, content expiration is another area that can really give a boost to page load times.  If you use Fiddler to watch the number of requests IE makes on a given page, you may notice that most of the images and icons are always given 304 Not Modified responses.  While it's great that these images aren't resent, it's still a connection the browser needs to make with the web server.  Multiply that by 20 or so images on a page, the page load time begins to suffer.

The real danger with setting a content expiration is:  you're essentially telling the client, "Go away for X amount of time, then recheck if the content has changed."  (You can set content to expire on a certain date, too, to better suit a deployment schedule.)  So the dangers are:  absolutely no dynamic content can have content expiration other than immediate (the default).  The second caveat is that any updates that affect functionality, such as Javascript files, images used for layouts, etc., make poor choices if you're thinking you'll update them frequently, or absolutely require that the end-user see the latest version.

Still, there's a few tricks to getting around these limitations.  Since Javascript files are notoriously problematic, assigning the version number (such as myjavascript_3-21-06.js) in the filename can yield the best of both worlds.  Assuming it's not a problem to repoint all the content files to use this new version, it's not a problem to deploy since clients will always grab the new version.  (This is where having templates, such as master pages and themes makes site maintainability shine.)

For ease of use, it's often best to have directories set aside for such categorization.  For example, most /images folders can be set to at least a 7 day expiration time.  To do this, select the folder in IIS and select the HTTP Headers tab, and set the expiration at your discretion.  When IIS servers content from the folder, it will send the expiration header.

If you don't think you have enough images on your page to make this worthwhile, I encourage you to open Fiddler, and watch how many requests are made on a given page.  If you see more than a few 304's, consider content expiration.  You'll be amazed at the difference in page load times.

Comments (1) -

Michael K. Campbell
Michael K. Campbell
3/24/2006 12:47:16 PM #

Excellent review of the options and pros/cons.


Comments are closed

My Apps

Dark Skies Astrophotography Journal Vol 1 Explore The Moon
Mars Explorer Moons of Jupiter Messier Object Explorer
Brew Finder Earthquake Explorer Venus Explorer  

My Worldmap

Month List