diff options
Diffstat (limited to 'apps/web/app/sw.ts')
| -rw-r--r-- | apps/web/app/sw.ts | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/apps/web/app/sw.ts b/apps/web/app/sw.ts index 0469377..e18cc5a 100644 --- a/apps/web/app/sw.ts +++ b/apps/web/app/sw.ts @@ -1,7 +1,7 @@ /// <reference lib="webworker" /> import { defaultCache } from "@serwist/next/worker" import type { PrecacheEntry, SerwistGlobalConfig } from "serwist" -import { Serwist } from "serwist" +import { Serwist, NetworkFirst, ExpirationPlugin } from "serwist" declare global { interface WorkerGlobalScope extends SerwistGlobalConfig { @@ -27,7 +27,25 @@ const serwist = new Serwist({ skipWaiting: true, clientsClaim: true, navigationPreload: true, - runtimeCaching: sameOriginCache, + runtimeCaching: [ + { + matcher: ({ url, request }) => + url.hostname.endsWith(".supabase.co") && + url.pathname.startsWith("/rest/v1/") && + request.method === "GET", + handler: new NetworkFirst({ + cacheName: "supabase-rest-get", + networkTimeoutSeconds: 10, + plugins: [ + new ExpirationPlugin({ + maxEntries: 200, + maxAgeSeconds: 60 * 60 * 24, + }), + ], + }), + }, + ...sameOriginCache, + ], }) serwist.addEventListeners() |