When programming desktop applications I’ve always been a supporter of lazy loading of objects but I’ve never given this much thought when creating websites. Until now. What happened you ask? Well, one of my sites got dugg earlier this week. As most of you know, this means a lot of visitors in a short period of time, often referred to as the Slashdot/Digg Effect. I’m planning on blogging on this experience in a bit, so I’ll skip that part for now (come back in a couple of days if you’re interested). So, let’s move on to …
Why is this a good idea for (some) websites
I’ll use the page that got dugg as an example. It’s basically a page with a video from Google Video with some controls on the right side which can be used for adding comments or sending the video to a friend.
A couple of facts: – These controls are AJAX based, and I use the infamous prototype.js for this. – prototype.js is 47k – About 0,03% of the visitors write comments/send e-mail and prototype.js is only used when this is done – When I was dugg, I used 1,7GB in bandwidth only for prototype.js!
Starting to get the picture?
So the clue would be to only include include.js when loading the page, and then using it’s include() function to retrieve prototype.js and the other files. This is only done the first time a user uses the controls on your page that needs the AJAX libraries. Of course, it would be a good idea to show that familiar ajax loading image when doing this ;)
Can’t wait to implement this on 43min.com.
Also, I plan on analyzing the digg effect in a post the next days, and also letting you know how Codeigniter handled the traffic (43min is built on CI) – so if this is stuff you find interesting you might want to subscribe to my feed.