Chrome : Hard reload images

Viewed 419

To hard refresh cached images I have tried multiple ways: like clearing localStorage and sessionStorage. Sending the Clear-Site-Data header also not clear cached images from the browser.

location.reload(true);//is now deprectaed which is also not helping here

But no luck, I'm still getting old images.

I want to achieve chrome's "Empty cache and Hard Reload" feature.

I don't want to go with making the image URL unique, as it's referred from 50+ places.

1 Answers

Check out the Cache.delete() Web API

https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete

This sample code may delete all cached items. Give it a try

caches.open('v1').then(function(cache) {
  cache.keys().then(function(keys) {
    keys.forEach(function(request, index, array) {
      cache.delete(request);
    });
  });
})
Related