Recently I have been playing around with a simple gallery system built for Zend Framework and one of the things I wanted to do was to be able to dynamically generate watermarked images and thumbnails.

Whilst debugging some javascript using firebug I noticed that the “dynamic” images (they don’t actually change) where not being cached. After a little poking around I found a rather useful blog post over at pjdietz.com stating that all you had to do was set a file modified header, then each image request check for this modified time.

Because my images do not change if the date exists that means the browser already has a up-to-date copy of the image and there is no point in doing all the processing again. So after adding this code I found that my images started to get cached!

According to firebug this reduces the image request time by over half. If you have a PHP script that generates images I would very much recommend using this, not only to reduce loading times but to reduce the load on your server too.