Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove image from browser cache

In my web app, I have a large collection of thumbnails, the user is able to select a thumbnail and client side recrop from the original image to recreate a new thumbnail.

That's fine, in my app, I just set the newly created image instantly to the image source, without reloading it from the server, and next to this, the new image is uploaded to the server. This is to ensure a very responsive feeling. The problem is that when to user refreshes the page, he sees the cached old version of the thumbnail.

I know I could use some image.jpg?sometimestamp to be sure the browser has to download a new version of the thumbnail, but as I said, the app needs to be very responsive, even on small &slow internet connections. (Thats why the app in itself is stored on the user's computer and not downloaded live. Only uploads, downloads and jsons are transitting)

The ideal solution would be to be able to tell the browser : remove this particular file from your cache : someurl.com/somefolder/image.jpg, so that the browser has to fetch it again when it needs it. is this possible and how?

So I'm not asking how not to cache files or how to force re-verification each call, I'm asking how I could remove some particular file from browser's cache.

ps: this can be a webkit-only solution as this is the only platform it is running on.(it is actually a qtwebkit on a Qt project.

like image 824
Vincent Duprez Avatar asked Sep 12 '13 07:09

Vincent Duprez


2 Answers

The function window.URL.revokeObjectURL() can solve your problem.

The URL.revokeObjectURL() static method releases an existing object URL which was previously created by calling window.URL.createObjectURL(). Call this method when you've finished using a object URL, in order to let the browser know it doesn't need to keep the reference to the file any longer.

For details: https://developer.mozilla.org/en-US/docs/Web/API/URL.revokeObjectURL

Note that this is an experimental function with limited cross-browser support.

like image 73
Xuesen Liang Avatar answered Sep 24 '22 18:09

Xuesen Liang


You can't. Append a ?[something_volatile] to the request when you need to download it again, and you'll get the same effect. That method won't take away any of the snappiness if you only change the appendage string when needed.

like image 44
Trevor Dixon Avatar answered Sep 25 '22 18:09

Trevor Dixon