diff --git a/client/scripts/pwa.js.php b/client/scripts/pwa.js.php index 7b35cfc..2085c28 100644 --- a/client/scripts/pwa.js.php +++ b/client/scripts/pwa.js.php @@ -8,7 +8,7 @@ //Loading the Service Worker if ('serviceWorker' in navigator) { window.addEventListener('load', function() { - // TODO navigator.serviceWorker.register('_service-worker.js', {scope: ''}); + navigator.serviceWorker.register('/service-worker.js.php'); }); } diff --git a/index.php b/index.php index 4f9a677..6b2f486 100644 --- a/index.php +++ b/index.php @@ -5,6 +5,8 @@ require_once(__DIR__ . '/server/templates.php'); require_once(__DIR__ . '/server/scripts.php'); + define('LINK_PRE', SERVER_ADDR . '/'); + $request = false; if (isset($_GET['request'])) { $request = explode('/', $_GET['request']); @@ -18,11 +20,10 @@ $site = ''; } if ($site == '') { - $site = 'index'; + header('Location: ' . LINK_PRE . 'index'); + exit; } - define('LINK_PRE', SERVER_ADDR . '/'); - if (!file_exists(__DIR__ . '/content/' . $site . '.php')) { $site = '404'; } diff --git a/service-worker.js.php b/service-worker.js.php new file mode 100644 index 0000000..3ee05b3 --- /dev/null +++ b/service-worker.js.php @@ -0,0 +1,90 @@ + +importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js'); + +//Workbox Config +workbox.setConfig({ + debug: false //set to true if you want to see SW in action. +}); + + +workbox.core.setCacheNameDetails({ + prefix: 'regatten-', + suffix: 'v1', + precache: 'regatten--precache', + runtime: 'regatten--runtime' +}); + + +workbox.precaching.precacheAndRoute([ + +], { + ignoreURLParametersMatching: [/.*/] +}); + + +workbox.routing.registerRoute( + ({request}) => { + if (request.destination === 'style') return true; + if (request.destination === 'script') return true; + if (request.destination === 'image') return true; + if (request.destination === 'font') return true; + return false; + }, + new workbox.strategies.StaleWhileRevalidate({ + }) +); + + +//Learn more about Service Workers and Configurations +//https://developers.google.com/web/tools/workbox/ \ No newline at end of file