refactor: 移除 Service Worker 离线缓存 + 统一注册引导文案

- 删除 sw.js、ServiceWorkerRegistrar、offline 页面
- 保留 manifest 和 PWA 图标(添加到主屏幕仍可用)
- 注册引导文案统一为"10 秒注册,无需手机号"
This commit is contained in:
2026-02-27 10:38:33 +08:00
parent 4cc9d66403
commit 3335f7f872
6 changed files with 4 additions and 109 deletions
-68
View File
@@ -1,68 +0,0 @@
const CACHE_NAME = "nowhatever-v1";
const PRECACHE_URLS = ["/", "/offline"];
self.addEventListener("install", (event) => {
event.waitUntil(
caches
.open(CACHE_NAME)
.then((cache) => cache.addAll(PRECACHE_URLS))
.then(() => self.skipWaiting())
);
});
self.addEventListener("activate", (event) => {
event.waitUntil(
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 { request } = event;
if (request.method !== "GET") return;
const url = new URL(request.url);
// API calls: network-only
if (url.pathname.startsWith("/api/")) return;
// Static assets (_next/static, icons, fonts): cache-first
if (
url.pathname.startsWith("/_next/static/") ||
url.pathname.match(/\.(png|jpg|svg|ico|woff2?)$/)
) {
event.respondWith(
caches.match(request).then(
(cached) =>
cached ||
fetch(request).then((response) => {
const clone = response.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(request, clone));
return response;
})
)
);
return;
}
// HTML pages: network-first, fallback to cache, then offline page
event.respondWith(
fetch(request, { cache: "no-cache" })
.then((response) => {
const clone = response.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(request, clone));
return response;
})
.catch(() => caches.match(request).then((cached) => cached || caches.match("/offline")))
);
});
+2 -2
View File
@@ -227,11 +227,11 @@ export default function BlindboxLobbyPage() {
whileTap={{ scale: 0.97 }}
>
<LogIn size={18} />
/
/
</motion.button>
<p className="mt-3 text-[11px] text-dim">
+ 10
10
</p>
</motion.div>
) : loadError ? (
+1 -2
View File
@@ -2,7 +2,7 @@ import type { Metadata, Viewport } from "next";
import { Geist } from "next/font/google";
import "./globals.css";
import GlobalUserBadge from "@/components/GlobalUserBadge";
import ServiceWorkerRegistrar from "@/components/ServiceWorkerRegistrar";
import PageTransition from "@/components/PageTransition";
import ToastProvider from "@/components/ToastProvider";
@@ -40,7 +40,6 @@ export default function RootLayout({
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
</head>
<body className={`${geistSans.variable} font-sans antialiased`}>
<ServiceWorkerRegistrar />
<ToastProvider>
<PageTransition>{children}</PageTransition>
<GlobalUserBadge />
-23
View File
@@ -1,23 +0,0 @@
"use client";
import { WifiOff } from "lucide-react";
export default function OfflinePage() {
return (
<div className="min-h-dvh flex flex-col items-center justify-center px-6 bg-background text-foreground">
<div className="w-16 h-16 rounded-2xl bg-surface flex items-center justify-center mb-6">
<WifiOff className="w-8 h-8 text-muted" />
</div>
<h1 className="text-xl font-bold text-heading mb-2"></h1>
<p className="text-secondary text-center mb-8">
</p>
<button
onClick={() => window.location.reload()}
className="px-6 py-3 bg-accent text-white rounded-xl font-medium active:scale-95 transition-transform"
>
</button>
</div>
);
}
+1 -1
View File
@@ -385,7 +385,7 @@ export default function MatchResult({
</p>
<p className="mt-1 text-xs text-muted">
+ 10
10
</p>
<Button
onClick={() => setShowAuth(true)}
-13
View File
@@ -1,13 +0,0 @@
"use client";
import { useEffect } from "react";
export default function ServiceWorkerRegistrar() {
useEffect(() => {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/sw.js", { updateViaCache: "none" }).catch(() => {});
}
}, []);
return null;
}