Honey I Shrunk the Website

Honey I Shrunk the KidsWeb pages should load fast. Period. It’s irritating for any reason to wait on a computer. As a web developer, so many of the factors that go into page loading speed are outside of our control. However, some of the biggest ones are fixable with a minimal amount of work. The effort isn’t really justified for every page, but high traffic pages (like the university homepage) are definitely worth it.

Formatting for speed

As a programmer, I much prefer to maintain nicely formatted code. But when you are after speed, the whitespace has got to go. You can reduce the size of your page significantly. Smaller code size = less bandwidth used = faster load times = win for everyone but the programmer. Removing whitespace is effective on the HTML of the page, stylesheets and JavaScript.

Beyond whitespace

With JavaScript you can optimize even further. Tools such as Google’s Closure-Compiler can not only remove whitespace, but perform some pretty hefty optimizations on your code. For our redesign, Closure-Compiler reduced a 38KB file down to 14KB – and size was only part of the speed benefits it gave.

All zipped and ready

In today’s world, why would you send uncompressed resources? Processing power is cheap – it’s network speeds that still seem to limit us. Text files such as HTML, CSS and JavaScript can easily be compressed on the fly by almost any modern web server – as long as you have the processing power to spare. That 14KB JavaScript file actually gzips down to a measly 5.2KB. That brings our combined savings on that file alone up to nearly 87%!

Compression Resources

Zero is less than something

Of course downloading nothing is always faster. Usage stats show us that we have a high degree of returning visitors to our homepage. By setting some pretty aggressive cache headers, users only have to request new HTML. All of the images, stylesheets and scripts can be loaded from what they got on their last visit.

Cache headers are somewhat confusing and can have unintended side effects. Google has a great article on the relevant cache headers: http://code.google.com/speed/page-speed/docs/caching.html

Tools of the trade

Optimizing your site for loading speed can be a daunting task. There are a few tools that make this easier. My personal favorite is Google Page Speed (an addon for FireBug). In addition to a prioritized list of suggestions, several optimizations can be run within the tool itself such as image optmization and whitespace removal.

This is the second post in a series about the techniques used in the 2010 redesign of the Missouri State homepage. Other posts in the series:

About Chad Killingsworth

Chad Killingsworth is the assistant director and technical lead for the office of web & new media at Missouri State University.
Follow me on twitter
This entry was posted in Redesign, Technical, Web and New Media, Web Redesign 2010 and tagged , , , . Bookmark the permalink.

6 Responses to Honey I Shrunk the Website

  1. Great post. Web pages that take to long annoy me, especially if it blocks the main content. The attention span of internet users is short and half of it shouldn’t be spent waiting.

  2. Thanks for the post. It would be interesting to have some figures regarding size and speed that can be achieved after optimization. The ZIP thing is pretty interesting. maybe you could write about this and mention some resources?

    Cheers,
    Boris Crismancich

  3. Danny Baggs says:

    Hey Chad,
    Great post.  I fall foul of leaving the whitespace but have focused on the others a lot.  You make a very good point about this and I have to admit that this is the first time I’ve heard about Google’s Closure Compiler.
    Many thanks,
    Dan

  4. Hey Chad, awesome post! I’ve used yahoos YUI compressor before http://developer.yahoo.com/yui/compressor/ and was wondering how the Google one compares. Very useful stuff to read, thank you! Markus

    • I used YUI compressor prior to Closure. I’m actually doing a YouTube video in the next few months that talks just about Closure, but for now here is some raw data:

      Original Packer YUI Compressor Closure (Simple Mode) Closure (Advanced Mode)
      % Size
      (bytes)
      100%
      (38,913)
      27.82%
      (10,825)
      43.08%
      (16,762)
      41.81%
      (16,269)
      36.83%
      (14,331)
      GZip size 33.18%
      (12,910)
      17.81%
      (6,929)
      17.83%
      (6,937)
      17.46%
      (6,794)
      16.43%
      (6,395)

      Closure is optimized for GZip and size doesn’t tell the whole story. For instance, Packer’s use of eval makes it one to avoid. And if you need more convincing, you should know that the JQuery team now uses Closure (simple mode) to compress the JQuery source.