now it is PWA
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
const CACHE = 'otaman-v1';
|
||||
const URLS = [
|
||||
'index.html',
|
||||
'style.css',
|
||||
'sim.png',
|
||||
'icon-192.png',
|
||||
'icon-512.png',
|
||||
'manifest.json',
|
||||
'des-bundle.js',
|
||||
];
|
||||
|
||||
self.addEventListener('install', e => {
|
||||
e.waitUntil(
|
||||
caches.open(CACHE).then(c => c.addAll(URLS))
|
||||
);
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('activate', e => {
|
||||
e.waitUntil(
|
||||
caches.keys().then(keys =>
|
||||
Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', e => {
|
||||
e.respondWith(
|
||||
caches.match(e.request).then(r => r || fetch(e.request).then(res => {
|
||||
const clone = res.clone();
|
||||
caches.open(CACHE).then(c => c.put(e.request, clone));
|
||||
return res;
|
||||
}))
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user