-
-
Save Security2431/153b11680a3bbb654a86ee024cf8f038 to your computer and use it in GitHub Desktop.
Revisions
-
jeffposnick revised this gist
Nov 5, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,8 +9,8 @@ if ('serviceWorker' in navigator) { } else { // updatefound is also fired for the very first install. ¯\_(ツ)_/¯ registration.addEventListener('updatefound', () => { registration.installing.addEventListener('statechange', (event) => { if (event.target.state === 'installed') { if (registration.active) { // If there's already an active SW, and skipWaiting() is not // called in the SW, then the user needs to close all their -
jeffposnick revised this gist
Oct 24, 2018 . 1 changed file with 11 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,15 @@ if ('serviceWorker' in navigator) { window.addEventListener('load', async function() { const registration = await navigator.serviceWorker.register('/service-worker.js'); if (registration.waiting && registration.active) { // The page has been loaded when there's already a waiting and active SW. // This would happen if skipWaiting isn't being called, and there are // still old tabs open. console.log('Please close all tabs to get updates.'); } else { // updatefound is also fired for the very first install. ¯\_(ツ)_/¯ registration.addEventListener('updatefound', () => { registration.installing.addEventListener('statechange', () => { if (updatedSW.state === 'installed') { if (registration.active) { // If there's already an active SW, and skipWaiting() is not @@ -26,7 +24,7 @@ if ('serviceWorker' in navigator) { } } }); }); } }); } -
jeffposnick created this gist
Oct 15, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ if ('serviceWorker' in navigator) { window.addEventListener('load', async function() { const registration = await navigator.serviceWorker.register('/service-worker.js'); // updatefound is also fired for the very first install. ¯\_(ツ)_/¯ registration.addEventListener('updatefound', () => { const updatedSW = registration.installing || registration.waiting; if (updatedSW.state === 'waiting') { // A bit of an edge case, just in case the new SW has already made // it to the waiting state by the time this code runs. // Being in the 'waiting' state implies there's already an active // SW, so we don't need to explicitly check for that. console.log('Please close all tabs get updates.'); } else { updatedSW.addEventListener('statechange', () => { if (updatedSW.state === 'installed') { if (registration.active) { // If there's already an active SW, and skipWaiting() is not // called in the SW, then the user needs to close all their // tabs before they'll get updates. console.log('Please close all tabs to get updates.'); } else { // Otherwise, this newly installed SW will soon become the // active SW. Rather than explicitly wait for that to happen, // just show the initial "content is cached" message. console.log('Content is cached for the first time!'); } } }); } }); }); }