OK so you have a great graphic design for your web pages, and photos and so on. You want them to be cached in your user's browser as they never change, and you want to save data transfer/bandwidth. However, you also have dynamic images which get regularly updated, and you don't want them to be cached. So what do you do?
This is forehead slappingly simple, but always overlooked! The usual method is the Pragma No-Cache which isn't always that reliable any way. However, this will (usually) prevent everything from being cached, including the static images such as those in your web site design. That will mean slower page load times, and increased data transfer/bandwidth.
If you have programmed your site in PHP there is a very simple solution! Simply add "?rand=<?=rand(1,1000);?>" to the end of dynamic image URLs. For example "/graph.jpg?rand=<?=rand(1,1000);?>". In other words, the images that are updated regularly, such as web cam, wind direction, etc. What this does is add a random number to the end of the image file name, and so the file name changes every time the page is reloaded! So your permanent graphics, such as design elements of your page, photos etc will be cached, but the dynamic images will never be cached! |