Created
February 7, 2019 15:36
-
-
Save ryanirelan/f32ad8018dd960f017822534650e1a71 to your computer and use it in GitHub Desktop.
Service worker registration code. For livestream at: https://craftquest.io/livestreams/what-are-service-workers
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
if ('serviceWorker' in navigator) { | |
window.addEventListener('load', function() { | |
navigator.serviceWorker.register('/sw.js', { | |
scope: "/" | |
}).then(function(registration) { | |
// Registration was successful | |
console.log('ServiceWorker registration successful with scope: ', registration.scope); | |
// Trim the caches on load | |
navigator.serviceWorker.controller && navigator.serviceWorker.controller.postMessage({ | |
command: "trimCaches" | |
}); | |
}).catch(function(err) { | |
// registration failed :( | |
console.log('ServiceWorker registration failed: ', err); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment