Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a single file from browser cache

i have an image in my page, the image is cached in the browser.

now i have deleted the image, however Because it was cached, the request does not go to the server, And it appears again.

so How can I delete it from the browser cache?

like image 958
IFink Avatar asked Dec 04 '25 14:12

IFink


1 Answers

No you cannot physically delete cached file. Instead you can generate link to the file dynamically, for example

<script type="text/javascript">
document.write('<img id="without-cache" src="image.jpg?v=' + new Date().getTime() + '" />');
</script>

and eventually change the source with different ?v= when you want to reload it without loading it from cache.

$("#without-cache").attr("src", "image.jpg?v=" + new Date().getTime());
like image 127
Piotr Uchman Avatar answered Dec 08 '25 01:12

Piotr Uchman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!