#native_company# #native_desc#

Prevent images from caching

By Dustin Schneider
on September 23, 2002

So, you’ve just made that cool back end database with uploading image support, yet, when the user uploads a new image it isn’t shown unless its a full refresh (shift-refresh). Well, I’ve solved the problem. No, you do not have to set annoying cache headers or any of that other nonsense. The fix is quite easy.

Let’s say you have an image:

<img src="someimage.png">

This will be cached on some browsers no matter how many headers you throw at it. So far, this has worked like a charm for me:

<img src="someimage.png?x=<?=uniqid((double)microtime()*1000000,1)?>">

You can of course just pass a random number and such, but as long as you pass a random variable to the graphic file it will force it to reload and no more caching! Hooray!

– Dustin Schneider