This file contains 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 characters
self.addEventListener('message', (event) => { | |
if (event.data && event.data.type === 'SKIP_WAITING') { | |
self.skipWaiting(); | |
} | |
}); |
This file contains 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 characters
navigator.serviceWorker.addEventListener('controllerchange', () => { | |
window.location.reload(); | |
}); |
This file contains 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 characters
let deferredPrompt; | |
window.addEventListener('beforeinstallprompt', e => { | |
e.preventDefault(); // prevent mini info bar popping up | |
deferredPrompt = e; | |
// show install button somewhere! | |
}); |
This file contains 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 characters
button.addEventListener('click', async () => { | |
deferredPrompt.prompt(); | |
// ... | |
}); |
This file contains 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 characters
button.addEventListener('click', async () => { | |
deferredPrompt.prompt(); | |
// ... | |
}); |
This file contains 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 characters
button.addEventListener('click', async () => { | |
deferredPrompt.prompt(); | |
const { outcome } = await deferredPrompt.userChoice; | |
if (outcome === 'accepted') button.setAttribute('hidden', '); | |
// Send an analytics event for either dismissed or accepted! | |
}); |
This file contains 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 characters
<script> | |
if ('serviceWorker' in navigator) { | |
window.addEventListener('load', () => { | |
navigator.serviceWorker.register('./sw.js'); | |
}); | |
} | |
// ... |
This file contains 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 characters
<script> | |
if ('serviceWorker' in navigator) { | |
window.addEventListener('load', () => { | |
navigator.serviceWorker.register('./sw.js'); | |
}); | |
} | |
setTimeout(() => { | |
const img = new Image(); |
This file contains 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 characters
self.addEventListener('install', event => { | |
// cache a cat SVG | |
event.waitUntil( | |
caches.open('static-v1') | |
.then(cache => cache.add('cat.svg')) | |
); | |
}); |
This file contains 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 characters
self.addEventListener('install', event => { | |
// cache a cat SVG | |
event.waitUntil( | |
caches.open('static-v1') | |
.then(cache => cache.add('cat.svg')) | |
); | |
}); | |
self.addEventListener('activate', event => { | |
clients.claim(); |