40 lines
811 B
JavaScript
40 lines
811 B
JavaScript
const CACHE_NAME = 'opal-ai-v2-cache';
|
|
const ASSETS = [
|
|
'./',
|
|
'./index.html',
|
|
'./style.css',
|
|
'./app.js',
|
|
'./manifest.json',
|
|
'https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js'
|
|
];
|
|
|
|
self.addEventListener('install', (e) => {
|
|
e.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => {
|
|
return cache.addAll(ASSETS);
|
|
})
|
|
);
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('activate', (e) => {
|
|
e.waitUntil(
|
|
caches.keys().then((keys) => {
|
|
return Promise.all(
|
|
keys.map((key) => {
|
|
if (key !== CACHE_NAME) return caches.delete(key);
|
|
})
|
|
);
|
|
})
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener('fetch', (e) => {
|
|
e.respondWith(
|
|
caches.match(e.request).then((res) => {
|
|
return res || fetch(e.request);
|
|
})
|
|
);
|
|
});
|