While this isn't technically an ASP tip, it's worth
mentioning anyway. What's the difference between these
two sets of HTML?
Set 1
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p>This is some text</p>
</body>
</html>
Set 2
<html><head><title>Page Title</title></head><body><p>This is some text</p></body></html>
I know what you're thinking... "That's easy... the first one's
readable!" and you're absolutely right, but readable by who?
While I whole-heartedly support readable code, most HTML is meant
to be read by browsers and not people. To a browser, the two
sets of code above are identical except for the fact that the first one
is over 50% larger (142 bytes vs. 90 bytes) and takes that much
longer to download and display!
Don't get me wrong, I'm not saying you should take out all your
spacing and carriage returns, but poorly written ASP can add a lot
of extra whitespace to the resulting HTML. This whitespace not
only slows everything
down, it actually causes more work for your web server and uses
more bandwidth. So take a look at your site's HTML every once
and a while and make sure it's not getting out of hand.
Note: I realize a lot of you are rolling your eyes and
shaking your head at this, but it really can make a difference.
I was recently working with a community-based portal site
who was having some performance problems. The HTML to their home
page was just under 33k. I was amazed to find that
without even breaking a sweat (and leaving almost all the formatting
intact!), we were able to cut it down to 24k!
Almost a third of the page was totally worthless spacing.
They were reluctant to strip all whitespace, but I'm
sure we could have gotten that page down to under 20k
pretty easily without really changing anything!
And if that doesn't convince you, take a look at the source to
Yahoo's homepage sometime. You'll find very few extraneous
tabs, spaces, and carriage returns. The most popular site on
the internet needs to do all they can to optimize and they certainly
took this tip to heart!
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.