fix: stabilize pro checkout loading
This commit is contained in:
+26
-8
@@ -1,5 +1,14 @@
|
||||
const CACHE_NAME = "polyweather-v1";
|
||||
const STATIC_ASSETS = ["/_next/", "/favicon"];
|
||||
const CACHE_NAME = "polyweather-v2";
|
||||
const CACHEABLE_PUBLIC_ASSETS = [
|
||||
"/favicon.ico",
|
||||
"/favicon-16x16.png",
|
||||
"/favicon-32x32.png",
|
||||
"/apple-touch-icon.png",
|
||||
"/android-chrome-192x192.png",
|
||||
"/android-chrome-512x512.png",
|
||||
"/manifest.webmanifest",
|
||||
"/site.webmanifest",
|
||||
];
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(self.skipWaiting());
|
||||
@@ -7,18 +16,27 @@ self.addEventListener("install", (event) => {
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((keys) =>
|
||||
Promise.all(
|
||||
keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key)),
|
||||
),
|
||||
),
|
||||
caches
|
||||
.keys()
|
||||
.then((keys) =>
|
||||
Promise.all(
|
||||
keys
|
||||
.filter((key) => key !== CACHE_NAME)
|
||||
.map((key) => caches.delete(key)),
|
||||
),
|
||||
)
|
||||
.then(() => self.clients.claim()),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
if (STATIC_ASSETS.some((prefix) => url.pathname.startsWith(prefix))) {
|
||||
// Do not cache-first Next.js build chunks. A user can keep an old app shell
|
||||
// open across deployments; if checkout UI is loaded later, stale/missing
|
||||
// chunks surface as a generic page fault. Let the browser/Vercel handle
|
||||
// immutable _next/static asset caching instead.
|
||||
if (CACHEABLE_PUBLIC_ASSETS.includes(url.pathname)) {
|
||||
event.respondWith(
|
||||
caches.open(CACHE_NAME).then((cache) =>
|
||||
cache.match(event.request).then(
|
||||
|
||||
Reference in New Issue
Block a user