refactor: 移除 Service Worker 离线缓存 + 统一注册引导文案
- 删除 sw.js、ServiceWorkerRegistrar、offline 页面 - 保留 manifest 和 PWA 图标(添加到主屏幕仍可用) - 注册引导文案统一为"10 秒注册,无需手机号"
This commit is contained in:
@@ -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")))
|
|
||||||
);
|
|
||||||
});
|
|
||||||
@@ -227,11 +227,11 @@ export default function BlindboxLobbyPage() {
|
|||||||
whileTap={{ scale: 0.97 }}
|
whileTap={{ scale: 0.97 }}
|
||||||
>
|
>
|
||||||
<LogIn size={18} />
|
<LogIn size={18} />
|
||||||
登录 / 注册,开始你的第一个盲盒
|
登录 / 注册
|
||||||
</motion.button>
|
</motion.button>
|
||||||
|
|
||||||
<p className="mt-3 text-[11px] text-dim">
|
<p className="mt-3 text-[11px] text-dim">
|
||||||
仅需用户名 + 密码,10 秒注册
|
10 秒注册,无需手机号
|
||||||
</p>
|
</p>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
) : loadError ? (
|
) : loadError ? (
|
||||||
|
|||||||
+1
-2
@@ -2,7 +2,7 @@ import type { Metadata, Viewport } from "next";
|
|||||||
import { Geist } from "next/font/google";
|
import { Geist } from "next/font/google";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
import GlobalUserBadge from "@/components/GlobalUserBadge";
|
import GlobalUserBadge from "@/components/GlobalUserBadge";
|
||||||
import ServiceWorkerRegistrar from "@/components/ServiceWorkerRegistrar";
|
|
||||||
import PageTransition from "@/components/PageTransition";
|
import PageTransition from "@/components/PageTransition";
|
||||||
import ToastProvider from "@/components/ToastProvider";
|
import ToastProvider from "@/components/ToastProvider";
|
||||||
|
|
||||||
@@ -40,7 +40,6 @@ export default function RootLayout({
|
|||||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||||
</head>
|
</head>
|
||||||
<body className={`${geistSans.variable} font-sans antialiased`}>
|
<body className={`${geistSans.variable} font-sans antialiased`}>
|
||||||
<ServiceWorkerRegistrar />
|
|
||||||
<ToastProvider>
|
<ToastProvider>
|
||||||
<PageTransition>{children}</PageTransition>
|
<PageTransition>{children}</PageTransition>
|
||||||
<GlobalUserBadge />
|
<GlobalUserBadge />
|
||||||
|
|||||||
@@ -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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -385,7 +385,7 @@ export default function MatchResult({
|
|||||||
注册后,决策记录和收藏不会丢失
|
注册后,决策记录和收藏不会丢失
|
||||||
</p>
|
</p>
|
||||||
<p className="mt-1 text-xs text-muted">
|
<p className="mt-1 text-xs text-muted">
|
||||||
仅需用户名 + 密码,10 秒完成
|
10 秒注册,无需手机号
|
||||||
</p>
|
</p>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => setShowAuth(true)}
|
onClick={() => setShowAuth(true)}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user