Created
March 9, 2018 18:20
-
-
Save AkimaLunar/07afd816bec0b0200f91c8744f45278b to your computer and use it in GitHub Desktop.
Service worker registration
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
// main.js | |
if (!('serviceWorker' in navigator)) { | |
console.log('sw not supported'); | |
return; | |
} | |
navigator.serviceWorker.register('/path/to/service-worker.js') // returns a Promise | |
.then(function(registration) { | |
console.log('SW registered! Scope is: ', registration.scope); | |
}); | |
//------------------------ | |
// service-worker.js | |
// Events: install, activate, message, fetch, sync, push... | |
self.addEventLister('activate', function(event) { | |
// Clean up stale sw's | |
}); | |
self.addEventListener('fetch', function(event) { | |
event.respondWith( | |
caches.match(event.request) | |
) | |
}); | |
//------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment