Created
October 16, 2016 00:01
-
-
Save keighty/ec1a37a0f6475d7cdf2db64b01eff445 to your computer and use it in GitHub Desktop.
Service worker example
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) { | |
navigator.serviceWorker.register('./sw.js') | |
.then(function(reg) { | |
if(reg.installing) { | |
console.log('Service worker installing on registration.'); | |
} else if(reg.waiting) { | |
console.log('Service worker installed on registration.'); | |
} else if(reg.active) { | |
console.log('Service worker already active on registration.'); | |
} | |
}).catch(function(error) { | |
console.log('Registration failed with ' + error); | |
}); | |
} |
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
<html> | |
<body> | |
<script src="./app.js"></script> | |
</body> | |
</html> |
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
console.log('inside registration script') | |
this.addEventListener('install', function(event) { | |
console.log('Service worker installed.') | |
}); | |
this.addEventListener('activate', function (event) { | |
console.log('Service worker activated.') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment