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 characters
module.exports = { | |
"globDirectory": ".", | |
"globPatterns": [ | |
"**/*.{js,html,json,css,lock}" | |
], | |
"swDest": "sw.js", | |
"swSrc": "src-sw.js" | |
}; |
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 characters
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js"); | |
console.log('Reading from src-sw.js'); | |
workbox.precaching.precacheAndRoute([]); |
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 characters
if ('serviceWorker' in navigator) { | |
// attach event listener on page l aod | |
window.addEventListener('load', () => { | |
// register serviceWorker withthe [sw.js] file | |
navigator.serviceWorker.register('/sw.js').then(registration => { | |
console.log('ServiceWorker registration successful with scope: ', registration.scope); |
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 characters
/** | |
* Welcome to your Workbox-powered service worker! | |
* | |
* You'll need to register this file in your web app and you should | |
* disable HTTP caching for this file too. | |
* See https://goo.gl/nhQhGp | |
* | |
* The rest of the code is auto-generated. Please don't update this file | |
* directly; instead, make changes to your Workbox build configuration | |
* and re-run your build process. |
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 characters
module.exports = { | |
"globDirectory": ".", | |
"globPatterns": [ | |
"**/*.{js,html,json,css,lock}" | |
], | |
"swDest": "sw.js" | |
}; |
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 characters
Notification.requestPermission(result => { | |
if (result === 'granted') { | |
showNotification('So nice to have you here!', 'Hey there!') | |
} | |
}); | |
function showNotification(title, message) { | |
if ('Notification' in window) { | |
navigator.serviceWorker.ready.then(registration => { | |
registration.showNotification(title, { |
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 characters
Notification.requestPermission(result => { | |
if (result === 'granted') { | |
if ('Notification' in window) { | |
navigator.serviceWorker.ready.then(registration => { | |
registration.showNotification('Vibration Sample', { | |
body: 'Buzz! Buzz!', | |
tag: 'vibration-sample' | |
}); | |
}); |
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 characters
Notification.requestPermission(result => { | |
if (result === 'granted') { | |
navigator.serviceWorker.ready.then(registration => { | |
registration.showNotification('Vibration Sample', { | |
body: 'Buzz! Buzz!', | |
tag: 'vibration-sample' | |
}); | |
}); | |
} | |
}); |
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 characters
Notification.requestPermission(result => { | |
console.log(result) | |
if (result === 'granted') { | |
alert('thanks for giving me permissions') | |
} | |
}); |
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 characters
self.addEventListener('fetch', e => { | |
console.log(caches) | |
e.respondWith( | |
caches.match(e.request).then(res => { | |
return res | |
}) | |
) | |
}) |