S Anand

HTTP download speeds

In some of the Web projects I’m working on, I have a choice of many small files vs few big files to download.

There are conflicting arguments. I’ve read that many small files are better, because you can choose to use only the required files, and they’ll be cached across the site. (These are typically CSS or Javascript files.) On the other hand, a single large file takes less time to download than the sum on many small files, because there’s less latency. (Latency is more important than bandwidth these days.)

I ran some tests, and the answer is rather easy. The graph below shows the average time taken to download a file of size 1KB – 100KB.

Time to download a file of size ranging from 1KB - 100KB

The X-axis is the size of the file. The Y-axis is the number of milliseconds taken to download the file, averaged over 10 attempts on my home computer. (I did the same thing at work and at a client site. The results are similar.)

The key thing is, it’s not linear. Larger files take less time. Specifically:

  • A file twice as big only takes 30% longer to load.
  • Breaking a file into two parts takes 54% longer to load.

These days, it looks like few big files are better.

To give you an example: my home page had the following components:

Size (KB) Load time (ms)
HTML 25 680
CSS 4 340
Javascript 6 400
Total 35 1420

The total time for these 3 files would be about 1.4 seconds. Instead, if I put them all on one file…

Size (KB) Load time (ms)
All-in-one 35 770

The combined file takes only 0.77 seconds — half the download time for split files. It’s a compelling argument to put all your CSS and Javascript (images, too, if possible) into a single page.

But what if people visit multiple pages on my site, and lose the benefit of caching? Not really. The benefit of caching is small. By having a single file, I have 770 – 680 = 90 ms additional time for each HTML to load. But I don’t have to load the CSS and Javascript individually, which takes 740 seconds. The breakeven is about 740 / 90 = 8 page visits.

So, on average, if people, visit more than 8 pages in my site, it’s worth breaking up the CSS and Javascript. But the average for my site is only 2 pages per person. (It’s a skewed distribution. Most, from Google, just visit one page. Few, from bookmarks, visit several pages. On average, it’s just over 2.) I’d argue that unless you’re using an external Javascript / CSS library (prototype, etc.) or people view many pages each visit, you’re better of having a single HTML+Javascript+CSS file.

Sparklines

John Resig has written a Sparklines library. Here’s an example. I wrote that HTTP download speeds not linear and that they flatten out over time. A linear line would look like this: The little red line here is a sparkline that’s based on real data. John’s javascript converts the data into a graph.

Sparklines were introduced by Edward Tufte.

Tamil old song lyrics quiz

Here are words from the middle of 15 old songs (before 1970). Can you guess which movie they are from?

Don’t worry about the spelling. Just spell it like it sounds, and the box will turn green.

How to access Gmail even if it is blocked

If you just want to check if you have new mail on Gmail, use Google’s personalised home page and add Gmail to the homepage. This shows new mail and a few words as a snippet.

If you want to read your mail, and don’t want to forward it to another account, use Google Groups as a backup to Gmail. Create a private Google Group and forward mails from Gmail to it. Google Groups often is not blocked, even if Gmail is.

Justin TV

The Truman Show is on for real, on Justin.TV.

Justin wears the camera 24 hours a day, 7 days a week. Even in the bathroom. Even on a date.

This is really live. Honest. Right now.

Justin will wear the camera until the day he dies. By which we mean if he takes it off, we’ll kill him.

The show has been on for 9 days till date.

Making a Media PC

Two weeks ago, I pulled together a Media PC.

This has been a long-term ambition. I’ve always wanted to have a PC as the centre of all my media. To use it as a radio, TV, stereo system, CD player, DVD player, etc.

I finally did it, for just under 1000 pounds.

Media PC Setup

At the centre of the setup is my 42″ Plasma TV (LG 42PC1D). I was debating between a plasma and LCD TV. The differences, as I understand them, are:

  1. Plasma TVs have a higher contrast ratio. My LG 42PC1D has a 10000:1 contrast ratio. An LG 42LC2D has a 1100:1 contrast ratio. The Plasma TV is also brighter (1500cd/m2) than the LCD TV (500cd/m2).
  2. Plasma TVs are cheaper for a given size. A 42″ LCD TV costs about 5-20% more.
  3. LCD TVs are lighter. The only reason this matters for me is if I carry the TV back home to India. But the shipping costs are exhorbitant anyway. So I’d be better off leaving the TV behind. And the weight becomes irrelevant.
  4. LCD TVs consume less power. And my power bill is quite high. But I replaced most of the bulbs in our house with energy-efficient ones. Hopefully it will balance out.
  5. LCD TVs work better with computers. If you leave an image on a plasma TV for a long time, it burns on the screen. Screensavers become a must.

I finally picked the Plasma TV, but it was a borderline decision.

The TV is hooked to a Cyberhome DVD player with DivX and a Freeview receiver. The DVD player lets me watch DivX movies I download as torrents. The Freeview player gives me over 40 free channels for casual viewing. (I don’t watch enough TV to need Sky TV.)

I bought an Intel Pentium III Tower that I bought on eBay. This is my “media PC”. I hooked this up to my TV (which has a PC input), a pair of Bose Mediamate speakers (a gift from my brother-in-law) with excellent sound response, and a Labtec webcam.

Two other components I bought were wireless: a Microsoft wireless keyboard and mouse to control the system from my sofa, and a Linksys cordless Skype phone (with a speakerphone), so that I could hold videoconferences on Skype while on the sofa.

Having set this up, I’m truly beginning to appreciate the convenience of wireless appliances. Right now, I can do any of the above things without gettin up from my sofa. My laptop, phone and wireless keyboard are always just a hand’s reach away! Here are some of the things I’ve been doing (wirelessly):

  1. Videoconferencing. I leave the computer on permanently. My parents or in-laws call me on Skype. The cordless phone rings. I can answer Skype calls directly from the phone. When I pick up the call, the webcam turns on automatically. We can sit on the sofa and speak, while they see us. I can turn on the TV and see them through their webcam. It’s a full-fledged wireless video-conference setup.
  2. Listening to radio. I use my laptop to connect wirelessly to my media PC using Remote Desktop, start up WinAmp, and pick a Shoutcast channel (which has a decent tamil channel list). The sound comes through the Bose speakers connected to the media PC, and I can control the volume from any room, using my laptop.
  3. Listening to MP3s. Ditto, except I turn on a playlist on WinAmp.
  4. Watching online videos. I turn on the TV, use my wireless keyboard, and connect to Google Video. Most of the time, I watch recent tamil movies or Google Techtalks.
  5. Watching TV. (Live from BD and ShareVDO being some choices.)
  6. Watching movies. I actually use “low tech” to do this. I record DivX files I download on to a DVD, and play them through my DVD player (which recognises DivX). On those occasions that I download WMV files, I play them through the computer.

With this setup, it’s easy to do more cool things, like a Truman-show like broadcast (which Justin.TV already does).