First Commit: serviceWorker.js (yet not running)
This commit is contained in:
parent
32b20cd1c1
commit
b0971ed56a
39
public/serviceWorker.js
Normal file
39
public/serviceWorker.js
Normal 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
|
Loading…
x
Reference in New Issue
Block a user