| 1 | 'use strict'; |
| 2 | |
| 3 | function 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 | |
| 12 | function 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 | |
| 24 | registerApp(); |
projects-timfalken-com verhalenboek