1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-11-25 15:46:17 +09:00

chore(sw): only proxies HTML requests (#9070)

* chore(sw): only proxies HTML requests

もはやHTMLじゃなさそうなリクエストにはSWで関与しないようにする

こうするといろいろな面倒事が解決するはず…たぶん

Resolve #9037
Resolve #9038

* align code style

* Update packages/sw/src/sw.ts

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
rinsuki 2022-09-10 19:25:32 +09:00 committed by GitHub
parent d4b146e77a
commit e60a6cc621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,16 @@ self.addEventListener('activate', ev => {
});
self.addEventListener('fetch', ev => {
let isHTMLRequest = false;
if (ev.request.headers.get('sec-fetch-dest') === 'document') {
isHTMLRequest = true;
} else if (ev.request.headers.get('accept')?.includes('/html')) {
isHTMLRequest = true;
} else if (ev.request.url.endsWith('/')) {
isHTMLRequest = true;
}
if (!isHTMLRequest) return;
ev.respondWith(
fetch(ev.request)
.catch(() => new Response(`Offline. Service Worker @${_VERSION_}`, { status: 200 }))