Add installable PWA support
This commit is contained in:
1 parent
0e118b6eaf
commit
310087ad84
4 files changed
+30
-1
No files matched your search
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "大学英语六级 · 90天打卡",
|
||||
"short_name": "CET-6 打卡",
|
||||
"description": "CET-6 90 天复习计划、云端打卡与复盘。",
|
||||
"lang": "zh-CN",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#eef4ff",
|
||||
"theme_color": "#1d4ed8",
|
||||
"icons": [{ "src": "/favicon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "any maskable" }]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
const CACHE = "cet6-shell-v1";
|
||||
const APP_SHELL = ["/", "/tasks", "/stats", "/review", "/manifest.webmanifest", "/favicon.svg"];
|
||||
self.addEventListener("install", event => event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(APP_SHELL)).then(() => self.skipWaiting())));
|
||||
self.addEventListener("activate", event => event.waitUntil(self.clients.claim()));
|
||||
self.addEventListener("fetch", event => {
|
||||
const request = event.request;
|
||||
if (request.method !== "GET" || new URL(request.url).origin !== location.origin) return;
|
||||
if (request.url.includes("/api/")) return;
|
||||
event.respondWith(fetch(request).then(response => { const copy = response.clone(); caches.open(CACHE).then(cache => cache.put(request, copy)); return response; }).catch(() => caches.match(request).then(found => found || caches.match("/"))));
|
||||
});
|
||||
Reference in new issue
Block a user