Recently on Stack Overflow a user asked if loading multiple images as a zip file was faster than loading images individually. As it turns out we asked this question at mod7 too on a previous project. It turns out there can be a huge performance gain. I helpful user over there responded with this:
…there is often little gain in file size when zipping png or jpg images. If there is a good gain in file size, then the downloading time can be offset against the unzipping time.
He makes some great points. Images are already a compressed format, so zipping them is likely not to result in a significantly file size difference. In our tests we even saw the file size increase slightly when a group was zipped together. But as it turns out this is not where we get our performance benefit.
An HTTP request is a multi-step process, there is a fair bit of hand shaking that goes on between the client and server, (a DNS lookup too if the client doesn’t know the server’s IP), these steps add up to a fairly significant amount of time. These steps are repeated for every request made to the server, so when dealing with a large number of requests, reducing them down to 1 results in a large speed increase. This is where we see a improvement when working with zipped image assets. If dealing with zipped text files you can see an even greater speed increase, since text based files have no compression.
Here is a simple benchmark demonstrating this:
You can grab the source to this test here.