Initial curated chimera source from a8ae5b1db07fb49926c94585e2718e5130330974
This commit is contained in:
commit
c737a37f71
531 files changed
+119270
No files matched your search
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
const CACHE = 'chimera-shell-v1';
|
||||
const SHELL = ['/offline.html', '/manifest.webmanifest', '/build/icon.png'];
|
||||
|
||||
self.addEventListener('install', event => {
|
||||
event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(SHELL)).then(() => self.skipWaiting()));
|
||||
});
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
event.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(key => key.startsWith('chimera-shell-') && key !== CACHE).map(key => caches.delete(key)))).then(() => self.clients.claim()));
|
||||
});
|
||||
|
||||
function cacheable(url) {
|
||||
return url.origin === self.location.origin && (url.pathname === '/manifest.webmanifest' || url.pathname === '/offline.html' || url.pathname === '/build/icon.png' || url.pathname.startsWith('/styles/') || url.pathname.startsWith('/modules/'));
|
||||
}
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
if (event.request.method !== 'GET') return;
|
||||
const url = new URL(event.request.url);
|
||||
if (event.request.mode === 'navigate') {
|
||||
event.respondWith(fetch(event.request).catch(() => caches.match('/offline.html')));
|
||||
return;
|
||||
}
|
||||
if (!cacheable(url)) return;
|
||||
const isIcon = url.pathname === '/build/icon.png';
|
||||
const cacheFallback = isIcon ? '/build/icon.png' : event.request;
|
||||
event.respondWith(
|
||||
fetch(event.request).then(response => {
|
||||
if (response.ok && response.type === 'basic') {
|
||||
caches.open(CACHE).then(cache => {
|
||||
cache.put(event.request, response.clone());
|
||||
if (isIcon) cache.put(cacheFallback, response.clone());
|
||||
});
|
||||
}
|
||||
return response;
|
||||
}).catch(() => caches.match(cacheFallback)),
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user