Optimize tablet load: defer health check, lighten service worker, drop Google Fonts.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-12 14:49:58 +08:00
parent f0bb40c605
commit 7e65349878
4 changed files with 338 additions and 285 deletions
+6 -25
View File
@@ -1,14 +1,10 @@
/**
* Trading Studio PWA Service Worker
* 缓存应用壳,支持离线打开已访问页面;API 请求始终走网络
* Trading Studio PWA Service Worker(轻量版)
* 仅处理导航请求,不拦截 Gradio 静态资源 — 避免平板端加载变慢
*/
const CACHE_NAME = "trading-studio-v1";
const SHELL = ["/", "/manifest.webmanifest"];
const CACHE_NAME = "trading-studio-v2";
self.addEventListener("install", (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(SHELL)).catch(() => {})
);
self.skipWaiting();
});
@@ -23,28 +19,13 @@ self.addEventListener("activate", (event) => {
self.addEventListener("fetch", (event) => {
const { request } = event;
const url = new URL(request.url);
// API / 文件上传 / Gradio 动态接口不走缓存
if (
request.method !== "GET" ||
url.pathname.startsWith("/gradio_api") ||
url.pathname.startsWith("/file=") ||
url.pathname.startsWith("/upload") ||
url.pathname.includes("call")
) {
// 仅缓存页面导航,Gradio JS/CSS/API 全部直连网络
if (request.method !== "GET" || request.mode !== "navigate") {
return;
}
event.respondWith(
fetch(request)
.then((response) => {
if (response.ok && url.origin === self.location.origin) {
const clone = response.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(request, clone));
}
return response;
})
.catch(() => caches.match(request).then((r) => r || caches.match("/")))
fetch(request).catch(() => caches.match("/"))
);
});