shellphone.app/app/service-worker/fetch.ts

14 lines
456 B
TypeScript
Raw Normal View History

2022-06-04 13:48:37 +00:00
import { ASSET_CACHE, cacheAsset } from "~/service-worker/cache-utils";
2022-06-01 21:56:37 +00:00
declare let self: ServiceWorkerGlobalScope;
2022-06-04 13:48:37 +00:00
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);
2022-06-01 21:56:37 +00:00
}
return fetch(event.request);
}