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

27 lines
504 B
TypeScript
Raw Normal View History

import {
cacheAsset,
cacheDocument,
cacheLoaderData,
isAssetRequest,
isDocumentGetRequest,
isLoaderRequest,
} from "./cache-utils";
2022-06-04 13:48:37 +00:00
2022-06-01 21:56:37 +00:00
declare let self: ServiceWorkerGlobalScope;
export default async function handleFetch(event: FetchEvent) {
if (isAssetRequest(event.request)) {
2022-06-04 13:48:37 +00:00
return cacheAsset(event);
2022-06-01 21:56:37 +00:00
}
if (isLoaderRequest(event.request)) {
return cacheLoaderData(event);
}
if (isDocumentGetRequest(event.request)) {
return cacheDocument(event);
}
2022-06-01 21:56:37 +00:00
return fetch(event.request);
}