Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Service worker registration code. For livestream at:
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