83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
/// <reference lib="esnext" />
|
|
/// <reference lib="webworker" />
|
|
import { defaultCache } from "@serwist/turbopack/worker";
|
|
import type { PrecacheEntry, SerwistGlobalConfig } from "serwist";
|
|
import { Serwist, CacheFirst } from "serwist";
|
|
|
|
// This declares the value of `injectionPoint` to TypeScript.
|
|
// `injectionPoint` is the string that will be replaced by the
|
|
// actual precache manifest. By default, this string is set to
|
|
// `"self.__SW_MANIFEST"`.
|
|
declare global {
|
|
interface WorkerGlobalScope extends SerwistGlobalConfig {
|
|
__SW_MANIFEST: (PrecacheEntry | string)[] | undefined;
|
|
}
|
|
}
|
|
|
|
declare const self: ServiceWorkerGlobalScope;
|
|
|
|
const serwist = new Serwist({
|
|
precacheEntries: self.__SW_MANIFEST,
|
|
precacheOptions: {
|
|
cleanupOutdatedCaches: true,
|
|
concurrency: 20,
|
|
directoryIndex: "index.html",
|
|
fallbackToNetwork: true,
|
|
},
|
|
disableDevLogs: true,
|
|
skipWaiting: true,
|
|
clientsClaim: true,
|
|
navigationPreload: true,
|
|
runtimeCaching: [
|
|
...defaultCache,
|
|
{
|
|
matcher: ({ url }) => url.hostname.includes('tile.openstreetmap.org') || url.pathname.includes('/tiles/'),
|
|
handler: new CacheFirst({
|
|
cacheName: 'excalibur-offline-map-tiles-v1',
|
|
}),
|
|
},
|
|
],
|
|
fallbacks: {
|
|
entries: [
|
|
{
|
|
url: "/",
|
|
matcher({ request }) {
|
|
return request.destination === "document";
|
|
},
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
serwist.addEventListeners();
|
|
|
|
/** From Gemini */
|
|
/*
|
|
import { defaultCache } from '@serwist/next/worker';
|
|
import type { PrecacheEntry, SerwistGlobalConfig } from 'serwist';
|
|
import { CacheFirst, Serwist } from 'serwist';
|
|
|
|
declare const self: ServiceWorkerGlobalScope &
|
|
SerwistGlobalConfig & {
|
|
__SW_MANIFEST: (string | PrecacheEntry)[];
|
|
};
|
|
|
|
const serwist = new Serwist({
|
|
precacheEntries: self.__SW_MANIFEST,
|
|
skipWaiting: true,
|
|
clientsClaim: true,
|
|
navigationPreload: true,
|
|
runtimeCaching: [
|
|
...defaultCache,
|
|
{
|
|
// Intercept map tile requests from standard OSM / tile servers
|
|
matcher: ({ url }) => url.hostname.includes('tile.openstreetmap.org') || url.pathname.includes('/tiles/'),
|
|
handler: new CacheFirst({
|
|
cacheName: 'excalibur-offline-map-tiles-v1',
|
|
}),
|
|
},
|
|
],
|
|
});
|
|
|
|
serwist.addEventListeners();
|
|
*/ |