BlueGit

projects-timfalken-com verhalenboek

Files

verhalenboek / web / assets / pwa.js

pwa.js

feat: maak Verhalenboek installeerbaar als webapp
timfa project_87242033_bot_b167a9be22027ad5a4b431d0ad8426c6 · pushed by timfa · 6 weeks ago
944696d3 History
pwa.js 702 B Download Raw
1'use strict';
2
3function appScope() {
4 let path = window.location.pathname;
5 if (!path.endsWith('/')) {
6 if (/\.[a-z0-9]+$/i.test(path)) path = path.replace(/[^/]*$/, '');
7 else path += '/';
8 }
9 return new URL(path, window.location.origin);
10}
11
12function registerApp() {
13 if (!('serviceWorker' in navigator)) return;
14 const scope = appScope();
15 const swUrl = new URL('sw.js', scope);
16 const current = document.currentScript;
17 if (current && current.src) {
18 const version = new URL(current.src).searchParams.get('v');
19 if (version) swUrl.searchParams.set('v', version);
20 }
21 navigator.serviceWorker.register(swUrl.href, { scope: scope.href }).catch(function () {});
22}
23
24registerApp();