| 1 | 'use strict'; |
| 2 | |
| 3 | // Zelfde document bij een hash-wissel. Zonder dit zet de browser het oude |
| 4 | // scrollpunt terug, ook als de shell uit de service worker komt. |
| 5 | if ('scrollRestoration' in history) history.scrollRestoration = 'manual'; |
| 6 | |
| 7 | function appScope() { |
| 8 | let path = window.location.pathname; |
| 9 | if (!path.endsWith('/')) { |
| 10 | if (/\.[a-z0-9]+$/i.test(path)) path = path.replace(/[^/]*$/, ''); |
| 11 | else path += '/'; |
| 12 | } |
| 13 | return new URL(path, window.location.origin); |
| 14 | } |
| 15 | |
| 16 | function registerApp() { |
| 17 | if (!('serviceWorker' in navigator)) return; |
| 18 | const scope = appScope(); |
| 19 | const swUrl = new URL('sw.js', scope); |
| 20 | const current = document.currentScript; |
| 21 | if (current && current.src) { |
| 22 | const version = new URL(current.src).searchParams.get('v'); |
| 23 | if (version) swUrl.searchParams.set('v', version); |
| 24 | } |
| 25 | navigator.serviceWorker.register(swUrl.href, { scope: scope.href }).catch(function () {}); |
| 26 | } |
| 27 | |
| 28 | registerApp(); |
projects-timfalken-com verhalenboek