BlueGit

projects-timfalken-com verhalenboek

Files

verhalenboek / web / assets / pwa.js

pwa.js

fix: scroll naar boven bij wisselen van dag
timfa project_87242033_bot_b167a9be22027ad5a4b431d0ad8426c6 · pushed by timfa · 5 weeks ago
8dd1bc1f History
pwa.js 918 B Download Raw
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.
5if ('scrollRestoration' in history) history.scrollRestoration = 'manual';
6
7function 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
16function 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
28registerApp();