views:

100

answers:

2

I have many many small images that are displayed on a user's profile and the loading of this page is horrible. The best solution is to sprite them all, but sadly I have too many images for that and only a few hundred are used per profile.

So, I'm trying to get the second best solution. What headers should I send? ETag? Expires? Cache-Control? Right now I have:

http://metaward.com/media/award/ofwjh3.png

Last-Modified   Sat, 11 Jul 2009 22:37:49 GMT
Cache-Control   max-age=2592000
Expires Tue, 29 Sep 2009 22:41:21 GMT

And an example page with lots of images (to show how slow they load, even when cached) :

http://metaward.com/6

Sometimes the user will also change their profile picture, but there is only one of those so I'm not as worried about caching.

+1  A: 

In this case you should use a "far future expires" to maximize cache hits. This means if you change an image, you need to give it a new name, but I can't imagine you're changing them often given that there are so many.

You really have 100s of images on the page, and you should sprite them. Perhaps there are some more common ones (your recommended) that you can start with to see whether it helps. Or maybe you could do a sprite of those "least likely to change".

ndp
By sprite them you mean convert them to an image map. That way you only have one large image to download which will minimise the number of http requests sent to the server and speed up the download. That would work well for the link you sent but may not always be appropriate.
Matt H
Here's a link for the far future expires header: http://www.askapache.com/htaccess/apache-speed-expires.html
ndp
@Matt Yes. Put all the images into one file, and then "tile" it. Let's say you have tiles 100x100. If you make it a background image, CSS for row 1, column 2 looks something like "background-position: -100, 0; width: 100; height: 100; overflow:hidden".
ndp
Well, I have 14,000 images which are 48x48. Each page will only use around 500 of them, but which 500 changes for each person (I have 300,000 people). And more people and images are added programatically. Think I should still sprite them?
Paul Tarjan
Yes. You'll probably never get the loading of 500 images to work smoothly. The browser is just going to struggle with that (at least in the near term).I don't know your data. You're going to have to figure out a logical strategy. Ideas: (a) maybe the order doesn't matter and you can sprite some common ones and always show those at the top of the page. The page will pop up faster initially. (b) make a custom image for each user with just their sprites (you can test this by making a screen shot of an existing page)
ndp
A: 

Caching might help a little when a visitor moves from profile to profile, and serving the images from different subdomains with persistent connections could help speed delivery but the real performance killer is simply the number of HTTP requests. If you can identify two or more images that appear together more than 50% of the time, it seems it would be worthwhile to combine them into a sprite in a regularly-scheduled offline process. If resources permit, it might even be possible to use a image manipulation library e.g. php-gd to combine and serve blocks of images at runtime.

Dave