Replace/Purge/Remove Cached Image (NOT Refresh)

爱⌒轻易说出口 提交于 2020-01-17 12:29:45

问题


I've read every question (I believe) about image caching and they mostly address the refesh issue. What I need to do instead, is to "get rid" once and for all of cached images loaded through a JS script.

Backrgound: as part of a tool available on a public website, I need to load images from random websites and analyze them, without the need for displaying them. In summary it's just a loop with a function like this (which works fine):

var img = new Image();
img.onload = function(){//analysys};    
img.src  = curImg.url;

The problem is that in the process there might be the occasional inappropriate image, which I can't leave on the user's device and asking the user to empty the browser's cache is truly the very last resort.

Having no control on the server side, I searched for ways to prevent client-side caching and tried the various META tags without success. The last idea I'm left with is to "trick" the browser into replacing a cached image with one that I provide, but I have no idea if this is something that can be done in JS at all (at least without "illegal" hacks).

Is there any way to get rid of the unwanted images?

来源:https://stackoverflow.com/questions/23842463/replace-purge-remove-cached-image-not-refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!