blob: b5cce5c0ebb8e992b44fab45c42c6eb05079915c [file] [log] [blame]
avm9996399bb77c2020-01-27 03:15:08 +01001var CACHE_NAME = 'linia-cache-v1';
2var urlsToCache = [
3 '.',
4 'js/index.js',
5 'css/index.css',
6 'info.php?view=0',
7 'info.php?view=1',
8 'js/views/l9n.js',
9 'css/views/l9n.css'
10];
11
12self.addEventListener('install', function(event) {
13 // Perform install steps
14 event.waitUntil(
15 caches.open(CACHE_NAME).then(cache => {
16 return cache.addAll(urlsToCache);
17 })
18 );
19});
20
21self.addEventListener('fetch', function(event) {
22 var request = event.request;
23 var url = new URL(request.url);
24 url.searchParams.delete("station");
25 request = new Request(url.toString());
26
27 event.respondWith(
28 caches.match(request).then(response => {
29 // Cache hit - return response
30 if (response) {
31 return response;
32 }
33
34 return fetch(event.request);
35 }).catch(err => {
36 console.error(err);
37 })
38 );
39});