how to clear or replace a cached image

后端 未结 20 1573
囚心锁ツ
囚心锁ツ 2020-11-29 02:04

I know there are many ways to prevent image caching (such as via META tags), as well as a few nice tricks to ensure that the current version of an image is shown with every

20条回答
  •  独厮守ぢ
    2020-11-29 02:29

    I usually do the same as @Greg told us, and I have a function for that:

    function addMagicRefresh(url)
    {
        var symbol = url.indexOf('?') == -1 ? '?' : '&';
        var magic = Math.random()*999999;
        return url + symbol + 'magic=' + magic;
    }
    

    This will work since your server accepts it and you don't use the "magic" parameter any other way.

    I hope it helps.

提交回复
热议问题