Service worker registration code :
(function () {
'use strict';
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/sw.js').then(function (registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}else{
console.log('Browser does not support service workers');
}
})();
Is it possible to check in the register block about the expiration time of service worker and update it programmatically?
Also any best practices while we are working on service-worker?