Thank you for adding that section. I had done some research and wanted to tweak your code a bit. Currenthing the registration.unregister() throws and error because registration is never defined. So this is what I have ended up using.
// Unregister the service workerif('serviceWorker'innavigator){navigator.serviceWorker.getRegistrations().then(function(registrations){for(letregistrationofregistrations){//unregister service worker for old domainregistration.unregister()}}).catch(function(err){// fail state, which is fine as we just don't want a service worker.console.log('Fail: ',err);});}caches.keys().then(keys=>Promise.all(keys.map(asynckey=>awaitcaches.delete(key)))).catch((err)=>console.error('Something went wrong: ',err));
Thank you for adding that section. I had done some research and wanted to tweak your code a bit. Currenthing the
registration.unregister()
throws and error because registration is never defined. So this is what I have ended up using.Yeah, you need to invoke the code within the registration "scope", as you need it to invoke the
unregister
method.