ServiceWorker: onfetchで何もしないように (#7195)
* Resolve #7192 * skip waiting * fix * refactor
This commit is contained in:
parent
6477ad2cfc
commit
6ce2231e70
|
@ -10,7 +10,6 @@ import { I18n } from '../../misc/i18n';
|
||||||
//#region Variables
|
//#region Variables
|
||||||
const version = _VERSION_;
|
const version = _VERSION_;
|
||||||
const cacheName = `mk-cache-${version}`;
|
const cacheName = `mk-cache-${version}`;
|
||||||
const apiUrl = `${location.origin}/api/`;
|
|
||||||
|
|
||||||
let lang: string;
|
let lang: string;
|
||||||
let i18n: I18n<any>;
|
let i18n: I18n<any>;
|
||||||
|
@ -27,15 +26,7 @@ get('lang').then(async prelang => {
|
||||||
|
|
||||||
//#region Lifecycle: Install
|
//#region Lifecycle: Install
|
||||||
self.addEventListener('install', ev => {
|
self.addEventListener('install', ev => {
|
||||||
ev.waitUntil(
|
self.skipWaiting();
|
||||||
caches.open(cacheName)
|
|
||||||
.then(cache => {
|
|
||||||
return cache.addAll([
|
|
||||||
`/?v=${version}`
|
|
||||||
]);
|
|
||||||
})
|
|
||||||
.then(() => self.skipWaiting())
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
@ -53,19 +44,9 @@ self.addEventListener('activate', ev => {
|
||||||
});
|
});
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
// TODO: 消せるかも ref. https://github.com/syuilo/misskey/pull/7108#issuecomment-774573666
|
|
||||||
//#region When: Fetching
|
//#region When: Fetching
|
||||||
self.addEventListener('fetch', ev => {
|
self.addEventListener('fetch', ev => {
|
||||||
if (ev.request.method !== 'GET' || ev.request.url.startsWith(apiUrl)) return;
|
// Nothing to do
|
||||||
ev.respondWith(
|
|
||||||
caches.match(ev.request)
|
|
||||||
.then(response => {
|
|
||||||
return response || fetch(ev.request);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
return caches.match(`/?v=${version}`);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue