Using multiple javascript service workers at the same domain but different folders

前端 未结 2 897
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 15:23

My website offers an array of web apps for each client. Each client has a different mix of apps that can be used.

Each web app is a hosted in a different folder.

2条回答
  •  我在风中等你
    2020-12-05 15:32

    I don't know, but the accepted answer didn't worked for me as it has typos as wells missing code I think. I am putting below what worked for me. Though I don't want to take away any credit from the accepted answer, but just adding a working code, which will help others.

    self.addEventListener('activate', (event) => {
      const cleanup = async () => {
        const cacheNames = await caches.keys();// here it should be caches
        console.log(cacheNames);
        const cachesToDelete = cacheNames.filter(      
        (cacheNames) => (cacheNames.startsWith(`${registration.scope}!`) && cacheNames !== CACHE_NAME));
        console.log(cachesToDelete); 
       // await Promise.all(cachesToDelete.map(caches.delete));// this line rewritten to make it working.
        await Promise.all(cachesToDelete.map(CACHE_NAME=>{ 
          return caches.delete(CACHE_NAME);
        })
        )    
      };  
      event.waitUntil(cleanup());
    });
    

提交回复
热议问题