// sw.js — Network-First 서비스 워커 const APP_VERSION = 'v2026040101'; const CACHE_NAME = 'tkfb-' + APP_VERSION; self.addEventListener('install', function() { self.skipWaiting(); }); self.addEventListener('activate', function(event) { event.waitUntil( caches.keys().then(function(keys) { return Promise.all( keys.filter(function(k) { return k !== CACHE_NAME; }) .map(function(k) { return caches.delete(k); }) ); }).then(function() { return self.clients.claim(); }) ); }); self.addEventListener('fetch', function(event) { // API, POST, cross-origin, 로그인/대시보드 프록시 경로는 캐싱하지 않음 if (event.request.url.includes('/api/')) return; if (event.request.method !== 'GET') return; if (!event.request.url.startsWith(self.location.origin)) return; var path = new URL(event.request.url).pathname; if (path === '/dashboard' || path === '/login' || path === '/auth' || path.startsWith('/auth/')) return; event.respondWith( fetch(event.request) .then(function(res) { if (res.ok) { var clone = res.clone(); caches.open(CACHE_NAME).then(function(c) { c.put(event.request, clone); }); } return res; }) .catch(function() { return caches.match(event.request); }) ); });