Repository navigation
Expand file tree
/
Copy pathsw.js
More file actions
112 lines (106 loc) · 2.88 KB
/
Copy pathsw.js
File metadata and controls
112 lines (106 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const CACHE = 'uwave-v20';
const ASSETS = [
'./',
'./index.html',
'./styles.css',
'./app.js',
'./geo-utils.js',
'./vincenty.js',
'./haversine.js',
'./dh-filter.js',
'./median.js',
'./smoother.js',
'./dh-filter-xyz.js',
'./smoother-xyz.js',
'./sound-speed.js',
'./gnss-parser.js',
'./webview-stub.js',
'./uw-protocol.js',
'./serial-manager.js',
'./uw-port.js',
'./uw-queue-manager.js',
'./uw-device-manager.js',
'./uw-tracking-engine.js',
'./uw-usbl-solver.js',
'./uw-vlbl-solver.js',
'./uw-vlbl-measurements.js',
'./uw-vlbl-store.js',
'./uw-vlbl-worker.js',
'./settings-storage.js',
'./tracks.js',
'./poi-manager.js',
'./log-storage.js',
'./logger.js',
'./log-analyzer.js',
'./export.js',
'./modules/ui-themes.js',
'./modules/ui-settings.js',
'./modules/ui-chat.js',
'./modules/ui-tracking.js',
'./modules/ui-addressing.js',
'./modules/ui-vlbl.js',
'./modules/ui-devices.js',
'./modules/ui-console.js',
'./modules/ui-export.js',
'./modules/ui-map.js',
'./modules/ui-ruler.js',
'./modules/ui-topo.js',
'./CHANGELOG.html',
'./docs/guide.html',
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE).then((cache) => {
// Загружаем файлы по одному, игнорируя ошибки
return Promise.all(
ASSETS.map(url =>
cache.add(url).catch(err =>
console.warn('[SW] Failed to cache:', url, err)
)
)
);
})
);
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
event.waitUntil(
Promise.all([
clients.claim(),
// Удаляем старые кэши
caches.keys().then((keys) => {
return Promise.all(
keys.filter((key) => key !== CACHE)
.map((key) => caches.delete(key))
);
})
])
);
});
self.addEventListener('fetch', (event) => {
// Не трогаем запросы на другие origin'ы (например, GitHub, docs.unavlab.com
// вне /uWaveSuite/, CDN и т.д.) — пусть идут в сеть как обычно.
const url = new URL(event.request.url);
if (url.origin !== location.origin) {
return;
}
if (event.request.mode === 'navigate') {
event.respondWith(
caches.match(event.request, { ignoreSearch: true }).then((cached) => {
if (cached) return cached;
return caches.match('./index.html').then((index) => {
return index || fetch(event.request);
});
})
);
return;
}
// Остальные запросы — cache-first с игнором query string.
// ignoreSearch: true позволяет найти в кэше ./app.js,
// даже если запрос идёт как ./app.js?v=15 или ./app.js?native=1.
event.respondWith(
caches.match(event.request, { ignoreSearch: true }).then((cached) => {
return cached || fetch(event.request);
})
);
});