Aug
10
2009

Performance Tuning Does Matter

The project I have been working on lately is very javascript heavy. Throughout the dev cycle we kept wanting to optimize, but we never got around to it. We released, everything worked, and it was fast - people were happy! Unfortunately those on a slow connection might not have seen things the same way. It turns out the page people would spend most of their time on was a fat 800K (in some cases closes to a 1MB!) I guess we shouldn't have put off optimization after all.

Whitespace in a file is nothing more than whitespace. (Revolutionary, I know!) I am no different than any other dev. I like my code on separate lines, I like my code indented, but why should a computer care? The same can be said for comments.

The first thing I did was minify our javascript and css. Essentially, this means all comments and all extra whitespace was stripped out. If done properly, nothing will change in the execution. However, make sure you thoroughly test because there were a few errors that were found after the fact. This one step alone brought our page size down to ~500KB.

The next step was to optimize our images. We were able to get about 20K out of this. Granted, this was site wide and the page in question only benefited from about a single KB, but I'll that that. I have actually worked on project where optimizing our images saved us about 100KB per response. I say per response because the images being sent back to the client were not cached.

Speaking of caching, the next thing I did was make sure all static content was cached on the client. In a perfect world content such as javascript, css, and images will be cached indefinitely. You can then version your files to make sure that the client will get the changes when you release. Luckily for me this was already being done, so I didn't have to tackle it.

My next move was to turn on compression in IIS. static compression was already happening, but I went and enabled dynamic compression. As expected, this significantly reduced the size of the response. Remember, nothing is free. When it comes to compression, a decrease in bandwidth means an increase in CPU. Personally, I consider that an easy trade off. CPUs are cheap. If you are going to be turning on compression, I highly recommend reading this post by Scott Forsyth.

With those out of the way, I turned to YSlow. Even though some of the recommendations are only applicable if you are a Yahoo or Google sized company, you can still glean some useful tips from it. All in all, The page size was reduced from 800KB to 200KB. A whopping %75!

Remember, performance should not be an afterthought. It is much easier to do things right the first time instead of going back and making the changes later. Your users will thank you for it.

Add comment




biuquote
Loading


AdSense

Software engineer by hobby and trade. When I am not sitting in front of a computer, you can find me playing with my kids. I am lucky enough to be married to my best friend and high school sweetheart. Life couldn't be better!

 

All content is mine, not my employers

Chronology

Tweets

stumped over a design in my app...:(
1 day ago via Silver Bird
RT @ramseyshow: Blake: US adds 243,000 jobs in January and unemployment rate drops to 8.3%, lowest in three years. (AP)
3 days ago via rowi
RT @jnonis: Amen! Walking with ppl does! RT @stephenNcollins I dare say that boycotting a business in the name of Jesus has never won an ...
3 days ago via rowi
@danctheduck wife and I are big tea drinkers though. That or water is about all we have
3 days ago via WindowsLive
@danctheduck lol. We go through 3 pots/day (pot is 30oz) brew at least 3 times or else It gets pricy :) breville tea maker ftw
3 days ago via WindowsLive
@danctheduck how do u brew your TKY? Usually do mine at 195 for 3:30
3 days ago via rowi
@danctheduck wait...now I see it. Stopping by next time I'm in seattle
3 days ago via rowi
Follow me on Twitter