shellphone.app/app/service-worker/fetch.ts
2022-06-04 15:48:37 +02:00

14 lines
456 B
TypeScript

import { ASSET_CACHE, cacheAsset } from "~/service-worker/cache-utils";
declare let self: ServiceWorkerGlobalScope;
export type FetchEventWithPreloadResponse = FetchEvent & { preloadResponse?: Promise<Response | undefined> };
export default async function handleFetch(event: FetchEventWithPreloadResponse) {
if (["font", "image", "script", "style"].includes(event.request.destination)) {
return cacheAsset(event);
}
return fetch(event.request);
}