mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-01 00:08:10 +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:
parent
fe048ab2e2
commit
16537d8c92
@ -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 }))
|
||||
|
Loading…
Reference in New Issue
Block a user