How to clear cache of service worker?

前端 未结 4 880
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 05:43

So, I have an HTML page with service worker, the service worker cache the index.html and my JS files.

The problem is when I change the JS, the change doesn\'t show u

4条回答
  •  暖寄归人
    2020-11-28 06:07

    If you know the cache name you can simply call caches.delete() from anywhere you like in the worker:

    caches.delete(/*name*/);
    

    And if you wanted to wipe all caches (and not wait for them, say this is a background task) you only need to add this:

    caches.keys().then(function(names) {
        for (let name of names)
            caches.delete(name);
    });
    

提交回复
热议问题