First Commit: serviceWorker.js (yet not running)

This commit is contained in:
Erik Römmelt 2018-11-12 00:17:21 +01:00
parent 32b20cd1c1
commit b0971ed56a

39
public/serviceWorker.js Normal file
View File

@ -0,0 +1,39 @@
'use strict';
// TODO: Instance var/const for version control and cache list
// NOTE: Registration
if ('serviceWorker' in navigator) {
// Register a service worker hosted at the root of the
// site using the default scope.
navigator.serviceWorker.register('/serviceWorker.js', {
scope: '/'
}).then(function (registration) {
return console.log('Service worker registration succeeded: ', registration);
}).catch(function (error) {
// registration failed
return console.log('Service worker registration failed: ', error);
});
} else {
console.log('Service workers are not supported.');
}
// NOTE: Install and activate: Populating cache
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open('v1').then(function (cache) {
return cache.addAll([
'/',
'/index.html',
'/style.css'
]);
})
);
});
// NOTE: Fetch structure
self.addEventListener('fetch', function(event) {
});
// NOTE: Activate structure <- TODO: Delete older cache versions