Skip to content

Instantly share code, notes, and snippets.

@keighty
Created October 16, 2016 00:01
Show Gist options
  • Save keighty/ec1a37a0f6475d7cdf2db64b01eff445 to your computer and use it in GitHub Desktop.
Save keighty/ec1a37a0f6475d7cdf2db64b01eff445 to your computer and use it in GitHub Desktop.
Service worker example
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);
});
}
<html>
<body>
<script src="./app.js"></script>
</body>
</html>
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