tags:

views:

113

answers:

2

I have a website that contains pages with many small images. The images are set to cache, with the headers containing:

Expires "Thu, 31 Dec 2037 23:55:55 GMT"
Cache-Control "public, max-age=315360000"

When someone loads a page, however, it seems that we are still forced to send a 304 response for each image--better than sending the whole image, but still takes some time. Of course, this sort of caching is up to the browser, but is it possible to suggest to the browser that it use the cached images without any request at all?

+1  A: 

Take a look at RFC 2616, Part of the HTTP/1.1 Protocol:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9

You'll see lots of options to play with. Primarily intended for proxies, not Browsers. You can't really force the browser to totally stop Modified-Since-Requests.

Especially older proxies might ignore your Cache-Control hints, see the mentioned paragraph on the aforementioned website:

Note that HTTP/1.0 caches might not implement Cache-Control and might only implement Pragma: no-cache (see section 14.32).

If you are really concerned about such short requests, take a look if HTTP-keepalive feature in your server is enabled (which has sideeffects on it's own, of course).

initall
+2  A: 

If you have many small images on a page, consider making a CSS sprite with all the images - that will reduce the number of requests a lot. A List Apart explains the concept.

Anders Fjeldstad
This is a great "low tech" alternative. Think of it as the image equivalent of combining your scripts and styles into single files.
David Meister
Of course, the best solution is to do both caching and to combine several files into one.
Anders Fjeldstad
This looks very promising--we have thousands of tiny 16x16 images, but we can put them into just a few reasonable sized images, and with those images cached, that should reduce our requests massively. Thank you!
Karptonite