fix: stabilize pro checkout loading

This commit is contained in:
2569718930@qq.com
2026-05-15 00:58:40 +08:00
parent f9154ff0f2
commit c4b1844a67
4 changed files with 63 additions and 21 deletions
+26 -8
View File
@@ -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(