Service worker precache

Yarn upgrades / cleanup
This commit is contained in:
2023-08-26 22:48:15 +01:00
parent 6fae5accde
commit 5cd1ad070a
26 changed files with 2885 additions and 4336 deletions

View File

@ -1,22 +1,14 @@
/// <reference lib="webworker" />
declare const self: ServiceWorkerGlobalScope;
declare const self: ServiceWorkerGlobalScope & {
__WB_MANIFEST: (string | PrecacheEntry)[]
};
import { clientsClaim } from "workbox-core";
import { registerRoute } from "workbox-routing";
import { CacheFirst } from "workbox-strategies";
import {PrecacheEntry, precacheAndRoute} from 'workbox-precaching';
precacheAndRoute(self.__WB_MANIFEST);
clientsClaim();
const staticTypes = ["image", "video", "audio", "script", "style", "font"];
const paths = ["/"];
registerRoute(
({ request, url }) =>
url.origin === self.location.origin && (staticTypes.includes(request.destination) || paths.includes(url.pathname)),
new CacheFirst({
cacheName: "static-content",
})
);
self.addEventListener("message", event => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();