2022-06-04 21:34:33 +00:00
|
|
|
import {
|
|
|
|
cacheAsset,
|
|
|
|
cacheDocument,
|
|
|
|
cacheLoaderData,
|
|
|
|
isAssetRequest,
|
|
|
|
isDocumentGetRequest,
|
|
|
|
isLoaderRequest,
|
|
|
|
} from "~/service-worker/cache-utils";
|
2022-06-04 13:48:37 +00:00
|
|
|
|
2022-06-01 21:56:37 +00:00
|
|
|
declare let self: ServiceWorkerGlobalScope;
|
|
|
|
|
2022-06-04 21:34:33 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-06-04 21:34:33 +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);
|
|
|
|
}
|