feat(pwa): Network-First 서비스 워커 — 홈화면 앱 자동 갱신

- sw.js: Network-First 캐시 전략 (GET + same-origin + res.ok만 캐시)
- tkfb-core.js: SW 등록 + 업데이트 감지 시 자동 새로고침
  (최초 설치 시 토스트 방지: controller 체크)
- manifest.json: start_url → dashboard-new.html
- nginx: sw.js, manifest.json no-cache 헤더
- 배포 시 sw.js의 APP_VERSION만 변경하면 전 사용자 자동 갱신

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-04-01 15:36:36 +09:00
parent 46a1f8310d
commit 1cfd4da8ba
41 changed files with 88 additions and 58 deletions

View File

@@ -2,7 +2,7 @@
"name": "TK 공장관리 - 테크니컬코리아",
"short_name": "TK공장",
"description": "테크니컬코리아 공장관리 시스템",
"start_url": "/pages/dashboard.html",
"start_url": "/pages/dashboard-new.html",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#1e40af",

View File

@@ -18,6 +18,14 @@ server {
add_header Cache-Control "no-store, no-cache, must-revalidate";
}
# SW, manifest 캐시 비활성화 (PWA 업데이트 즉시 반영)
location = /sw.js {
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
location = /manifest.json {
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# 정적 파일 캐시 (JS, CSS, 이미지 등)
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf)$ {
expires 1h;

View File

@@ -190,7 +190,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script type="module">

View File

@@ -314,7 +314,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script type="module">

View File

@@ -190,7 +190,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script type="module">

View File

@@ -135,7 +135,7 @@
</div>
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/static/js/purchase-analysis.js?v=2026040103"></script>
</body>
</html>

View File

@@ -507,7 +507,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script>
let currentReportId = null;

View File

@@ -390,7 +390,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>

View File

@@ -234,7 +234,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>

View File

@@ -70,7 +70,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>

View File

@@ -162,7 +162,7 @@
<!-- Toast -->
<div id="toastContainer" class="toast-container"></div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031701"></script>
<script src="/js/monthly-comparison.js?v=2026040109"></script>
<script>initAuth();</script>

View File

@@ -489,7 +489,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>

View File

@@ -104,7 +104,7 @@
<!-- Toast -->
<div id="toastContainer" class="toast-container"></div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031701"></script>
<script src="/js/my-monthly-confirm.js?v=2026040106"></script>
<script>initAuth();</script>

View File

@@ -267,7 +267,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>

View File

@@ -353,7 +353,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script type="module" src="/js/vacation-allocation.js" defer></script>
<script>initAuth();</script>

View File

@@ -130,7 +130,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="/js/vacation-common.js"></script>

View File

@@ -123,7 +123,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="/js/vacation-common.js"></script>

View File

@@ -215,7 +215,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="/js/vacation-common.js"></script>

View File

@@ -117,7 +117,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="/js/vacation-common.js"></script>

View File

@@ -286,7 +286,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>

View File

@@ -47,7 +47,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/production-dashboard.js?v=2026040103"></script>
<script src="/static/js/shared-bottom-nav.js?v=2026040103"></script>
</body>

View File

@@ -324,7 +324,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script type="module" src="/js/modern-dashboard.js?v=2026031401"></script>
<script type="module" src="/js/group-leader-dashboard.js?v=2026031401"></script>

View File

@@ -209,7 +209,7 @@
}, 50);
})();
</script>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="/js/daily-patrol.js?v=2026031401"></script>
<script>initAuth();</script>

View File

@@ -304,7 +304,7 @@
}, 50);
})();
</script>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="/js/zone-detail.js?v=2026031401"></script>
<script>initAuth();</script>

View File

@@ -320,7 +320,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script type="module" src="/js/my-profile.js"></script>
<script>initAuth();</script>

View File

@@ -390,7 +390,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script>initAuth();</script>
<script src="/js/change-password.js?v=2026040101"></script>
</body>

View File

@@ -97,7 +97,7 @@
<div class="pm-sheet-body" id="detailContent"></div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/static/js/purchase-request-mobile.js?v=2026040104"></script>
<script src="/static/js/shared-bottom-nav.js?v=2026040103"></script>
</body>

View File

@@ -312,7 +312,7 @@
</div>
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/static/js/purchase-request.js?v=2026040104"></script>
</body>
</html>

View File

@@ -277,7 +277,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script type="module" src="/js/work-analysis.js?v=2026031401"></script>

View File

@@ -163,7 +163,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031701"></script>
<script src="/js/daily-status.js?v=2026033001"></script>
</body>

View File

@@ -193,7 +193,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/meeting-detail.js?v=2026031701"></script>
</body>
</html>

View File

@@ -80,7 +80,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/meetings.js?v=2026031701"></script>
</body>
</html>

View File

@@ -114,7 +114,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031701"></script>
<script src="/js/proxy-input.js?v=2026033202"></script>
<script>initAuth();</script>

View File

@@ -190,7 +190,7 @@
</div>
<!-- 공통 모듈 -->
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="/js/common/utils.js?v=2026031401"></script>
<script src="/js/common/base-state.js?v=2026031401"></script>

View File

@@ -149,7 +149,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031401"></script>
<script src="/js/common/utils.js?v=2026031401"></script>
<script src="/js/common/base-state.js?v=2026031401"></script>

View File

@@ -347,7 +347,7 @@
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/schedule.js?v=2026031701"></script>
<script>
// 표준공정 생성 모달

View File

@@ -843,7 +843,7 @@
</div>
<!-- Scripts -->
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026040101"></script>
<!-- 공통 모듈 -->
<script src="/js/common/utils.js?v=2026040101"></script>

View File

@@ -264,7 +264,7 @@
</div>
<!-- 공통 모듈 -->
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026040101"></script>
<script src="/js/common/utils.js?v=2026040101"></script>
<script src="/js/common/base-state.js?v=2026040101"></script>

View File

@@ -573,7 +573,7 @@
<!-- 토스트 -->
<div class="toast-container" id="toastContainer"></div>
<script src="/static/js/tkfb-core.js?v=2026040104"></script>
<script src="/static/js/tkfb-core.js?v=2026040105"></script>
<script src="/js/api-base.js?v=2026031602"></script>
<script src="/js/common/utils.js?v=2026031602"></script>
<script src="/js/common/base-state.js?v=2026031602"></script>

View File

@@ -1,9 +1,18 @@
/* ===== 서비스 워커 해제 (push-sw.js 제외) ===== */
/* ===== 서비스 워커 등록 (Network-First 캐시) ===== */
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then(function(regs) { regs.forEach(function(r) {
if (!r.active || !r.active.scriptURL.includes('push-sw.js')) { r.unregister(); }
}); });
if (typeof caches !== 'undefined') { caches.keys().then(function(ns) { ns.forEach(function(n) { caches.delete(n); }); }); }
navigator.serviceWorker.register('/sw.js').then(function(reg) {
// 기존 SW가 있을 때만 업데이트 감지 (최초 설치 시 토스트 방지)
if (!navigator.serviceWorker.controller) return;
reg.addEventListener('updatefound', function() {
var newSW = reg.installing;
newSW.addEventListener('statechange', function() {
if (newSW.state === 'activated') {
showToast('새 버전이 적용되었습니다.', 'info');
setTimeout(function() { location.reload(); }, 1500);
}
});
});
});
}
/* ===== Config ===== */

View File

@@ -1,7 +1,8 @@
// sw.js - Service Worker 자체 해제 (캐시 초기화)
// 기존 SW를 교체하여 모든 캐시를 삭제하고 자체 해제합니다.
// sw.js — Network-First 서비스 워커
const APP_VERSION = 'v2026040101';
const CACHE_NAME = 'tkfb-' + APP_VERSION;
self.addEventListener('install', function(event) {
self.addEventListener('install', function() {
self.skipWaiting();
});
@@ -9,20 +10,32 @@ self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then(function(keys) {
return Promise.all(
keys.map(function(key) {
console.log('SW: 캐시 삭제:', key);
return caches.delete(key);
})
keys.filter(function(k) { return k !== CACHE_NAME; })
.map(function(k) { return caches.delete(k); })
);
}).then(function() {
console.log('SW: 모든 캐시 삭제 완료, 자체 해제');
return self.registration.unregister();
}).then(function() {
return self.clients.matchAll();
}).then(function(clients) {
clients.forEach(function(client) {
client.postMessage({ type: 'SW_CLEARED' });
});
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;
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);
})
);
});