summaryrefslogtreecommitdiff
path: root/static/sw.js
blob: edf814947dc12664f1dc256068add4ea7393bd43 (plain)
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
const CACHE_NAME = 'cl-bbs-v2';
const ASSETS = [
  '/static/styles/themes/default.css',
  '/static/styles/themes/dark.css',
  '/static/styles/themes/no.css',
  '/static/styles/themes/colored.css',
  '/static/styles/themes/matrix.css',
  '/static/favicon.ico',
  '/static/schemebbs.png'
];

self.addEventListener('install', (event) => {
  event.waitUntil(
    caches.open(CACHE_NAME).then((cache) => {
      return cache.addAll(ASSETS);
    })
  );
});

self.addEventListener('fetch', (event) => {
  event.respondWith(
    caches.match(event.request).then((cachedResponse) => {
      if (cachedResponse) {
        return cachedResponse;
      }
      return fetch(event.request).catch(() => {
        // Fallback or offline page
      });
    })
  );
});