Jump to content

Recommended Posts

 

Hi, it's been a while since i was on here... luckily i've been very busy :).. I have a slight issue to do with the caching of images in a CMS service site I built:

 

A client to the CMS site can upload images

The client has the option to upload new and overwrite their existing images

By the architecture of the system, if an image is uploaded to replace an existing one its name is kept the same, eg  image0023.jpg

This posed a problem with the browsers caching, it meant that although the image had changed on the server, the browser was not downloading the new as it thought it already had it in the cache... As a work around to just using a blanket no-cache meta I used the method which places a random string after the image source:

<img src="image0023.jpg?1234567"/>

 

When the page is reloaded the random string is no longer there on the image.

 

THE RESULT:

75% of the time it all works correctly and the correct images are displayed... however sometimes when the ?123456 is removed after a page reload the browser goes ahead and displays the old image that was cached...

 

MY POSSIBLE SOLUTION (for the 25% fail)

Accompany all images to be displayed on screen with their own unique ?randomString and store the said strings in a database along with the clients id and image id. The said strings to be a time stamp, or something similar, and renewed each time the image is replaced or edited.

Hopefully this will mean the browser will cache more than just the striaght forward file name thus never display an out of date image and as there is no meta no-cache my bandwidth may be saved a little...

 

I'm very keen to here what other peoples opinions on this might be, or if there is another way or better way or issues i may hit trying the above solution...

 

 

Thanks a lot,

 

John

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/255258-cms-image-cache-workaround/
Share on other sites

But if I did that then the clients browser would be forced to download the entire site again from scratch would it not, ie all js, css and all images...

 

I've been hunting for a while now but i cannot find a way to force browsers to clear a specific caches items and the above is the only solution i can think of

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.