From b0971ed56a5aebb72ee97e27e834ad986b815dcb Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Mon, 12 Nov 2018 00:17:21 +0100 Subject: [PATCH] First Commit: serviceWorker.js (yet not running) --- public/serviceWorker.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 public/serviceWorker.js diff --git a/public/serviceWorker.js b/public/serviceWorker.js new file mode 100644 index 0000000..d24de20 --- /dev/null +++ b/public/serviceWorker.js @@ -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