Browse Source

First Commit: serviceWorker.js (yet not running)

pull/1/head
Erik Römmelt 6 years ago
parent
commit
b0971ed56a
1 changed files with 39 additions and 0 deletions
  1. 39
    0
      public/serviceWorker.js

+ 39
- 0
public/serviceWorker.js 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

Loading…
Cancel
Save