Init
This commit is contained in:
1 parent
dd596f16b9
commit
3c052a8b43
25 files changed
+2252
-74
No files matched your search
@@ -0,0 +1,75 @@
|
||||
/// <reference lib="esnext" />
|
||||
/// <reference lib="webworker" />
|
||||
import { defaultCache } from "@serwist/turbopack/worker";
|
||||
import type { PrecacheEntry, SerwistGlobalConfig } from "serwist";
|
||||
import { Serwist } 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,
|
||||
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();
|
||||
*/
|
||||
Reference in new issue
Block a user