Javascript Widget Performance
I received the following question today from Rustin over at The Blog Frog, a cool community service for mommy bloggers:
Like MBL, we use external javascript that is referenced from the blog. If our site ever goes down, even for 2 minutes, browsers try to load the javascript and pause for 30 seconds. Publishers then get upset that we are blocking their blog and take us off. How did you get around this with MBL? How did you display real-time data (when user visits their picture immediately shows up), but decouple from the database (which I assume was necessary)?
Since we have been asked this question more times than I can count, I figured it was time to post a quick response on the blog so anyone who is interested could benefit...
Keeping the javascript from slowing sites down was absolutely the biggest technical challenge on MyBlogLog. Once we sold MyBlogLog to Yahoo! we designed a massive, redundant architecture across multiple colos and countries to solve the performance issues. That said, there are a number of things that anyone can do on the cheap to improve performance. Off the top of my head, you could do any/all of the following:
- Move to an ajax/asynchronous load of the javascript widget.
- Move the main javascript to a CDN where you shouldn't have slowdowns.
- Have the CDN javascript call your servers to populate data, but gracefully timeout if it doesn't get a fast enough response.
- Move all member data into Memcached or similar memory caching layer on your servers.
- Make sure all javascript tags are set to defer load -- though browsers don't always implement this correctly.
- Use AmazonAWS or similar to setup multiple colos near users on the cheap.
- Move the tracking script lower in the page so it doesn't slow things down.
Finally, and most importantly, the system doesn't need to *be* real-time. It just needs to *act* like it is real-time. We had a line in the javascript on MyBlogLog that automatically showed the current user visiting the site at the top of the list. No database calls were needed. Even better, since the user didn't have a clue who had visited the site just before them, we could cache the list of recent visitors every minute -- longer for sites with low traffic -- and show it below the current user. This had a significant improvement in the end-user experience while costing us nothing.