Skip to content

Commit

Permalink
Merge pull request #2355 from gdg-x/unregister
Browse files Browse the repository at this point in the history
Default to safe service worker
  • Loading branch information
abraham authored Apr 4, 2022
2 parents 2b0fb97 + a602462 commit 39280d7
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions public/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
/**
* @license
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
* Default service worker unregisters itself and clears all caches. This is to
* help prevent installed/bad service workers from interfering with the app.
*
* Production deploys will generate a custom service worker that will overwrite
* this file.
*/
console.info('Service worker disabled for development, will be generated at build time.');
console.info('Service worker disabled for development.');

async function unregisterAndClearCaches() {
const unregisterPromise = self.registration.unregister();

const allCaches = await caches.keys();
const cacheDeletionPromises = allCaches.map((cache) => caches.delete(cache));

await Promise.all([unregisterPromise, ...cacheDeletionPromises]);

console.info('Service worker unregistered and cache cleared.');
}

unregisterAndClearCaches().catch((error) =>
console.error(`Error unregistering service worker: ${error}`)
);

0 comments on commit 39280d7

Please sign in to comment.