0
self.addEventListener('activate', event => {
  // delete any caches that aren't in expectedCaches
  event.waitUntil(
    caches.keys().then(keys => Promise.all(
      keys.map(key => {
        if (!expectedCaches.includes(key)) {
          return caches.delete(key);
        }
      })
    )).then(() => {
      self.clients.claim();
      console.log('myCache-v1 now ready to handle fetches!');
    })
  );
});

I want to minimize the cache update time. Instead of deleting the entire cache and replace. I want to update only changed files.

Problem I faced: User is not online so long time. It will check and update full cache then it replace.

Nunmuthu
  • 1
  • 1
  • Service worker run under a different thread not on main application UI so it will not impact your application performance at all. Also, to identify and update individual cache will require more time then replacing the entire cached. – Vimal Patel Dec 08 '20 at 07:37
  • Thanks @VimalPatel for you comment thats clarify my doubt. I found everywhere they are replacing the cache and not replacing the actual file. Is there a way we can do that? – Nunmuthu Dec 10 '20 at 09:35
  • Check out my answer here [Link](https://stackoverflow.com/questions/64517561/how-to-load-website-offline-from-base-url-using-service-workers-and-cache-api/64524996#64524996) – Vimal Patel Dec 10 '20 at 10:31

0 Answers0