From 7c80f5ce7e44b95d16e19de40de0f8079377c6b9 Mon Sep 17 00:00:00 2001 From: yyamashita Date: Sat, 22 Aug 2026 19:21:12 +0900 Subject: Initial commit: todo app with passkey auth and PWA support Co-Authored-By: Claude Sonnet 4.6 --- public/sw.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 public/sw.js (limited to 'public/sw.js') diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000..f4e6631 --- /dev/null +++ b/public/sw.js @@ -0,0 +1,26 @@ +const CACHE = "todo-v1"; +const PRECACHE = ["/manifest.json", "/icons/icon-192.png", "/icons/icon-512.png"]; + +self.addEventListener("install", (e) => { + e.waitUntil(caches.open(CACHE).then((c) => c.addAll(PRECACHE))); + self.skipWaiting(); +}); + +self.addEventListener("activate", (e) => { + e.waitUntil( + caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))) + ); + self.clients.claim(); +}); + +self.addEventListener("fetch", (e) => { + const url = new URL(e.request.url); + if (url.pathname.startsWith("/icons/") || url.pathname === "/manifest.json") { + e.respondWith(caches.match(e.request).then((r) => r || fetch(e.request))); + return; + } + // Network-first for everything else (SSR pages, API) + e.respondWith( + fetch(e.request).catch(() => caches.match(e.request)) + ); +}); -- cgit v1.2.3