차량 모니터 서비스워커 인증 캐시 제외
This commit is contained in:
@@ -66,6 +66,8 @@ Car는 차량 모뎀/게이트웨이에서 받은 상태를 수집해 DB에 저
|
|||||||
|
|
||||||
`asset-version.php`는 차량 모니터의 PHP/JS/CSS/manifest/icon 파일을 읽어 크기, 수정 시각, sha256 hash를 묶은 버전을 만듭니다. `assets/asset-reload.js`는 열린 모니터 화면에서 이 값을 확인하고, 달라지면 Cache Storage를 비운 뒤 현재 화면을 다시 엽니다.
|
`asset-version.php`는 차량 모니터의 PHP/JS/CSS/manifest/icon 파일을 읽어 크기, 수정 시각, sha256 hash를 묶은 버전을 만듭니다. `assets/asset-reload.js`는 열린 모니터 화면에서 이 값을 확인하고, 달라지면 Cache Storage를 비운 뒤 현재 화면을 다시 엽니다.
|
||||||
|
|
||||||
|
`sw.js`는 아이콘과 manifest 같은 정적 자산만 캐시합니다. `monitor.php`, 인증 요청, AJAX/usage 같은 PHP 응답은 인증 쿠키와 실시간 상태가 엮이므로 service worker 캐시 대상에서 제외합니다.
|
||||||
|
|
||||||
## 데이터/저장소
|
## 데이터/저장소
|
||||||
|
|
||||||
- Car DB tables: 차량 상태, 로그, 차트용 기록, TCP 요청 큐
|
- Car DB tables: 차량 상태, 로그, 차트용 기록, TCP 요청 큐
|
||||||
|
|||||||
+3
-1
@@ -3350,7 +3350,9 @@ $carMonitorSession = car_monitor_launcher_session();
|
|||||||
<script>
|
<script>
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
navigator.serviceWorker.register('/car/sw.js', {scope: '/car/'}).catch(() => {});
|
navigator.serviceWorker.register('/car/sw.js', {scope: '/car/'})
|
||||||
|
.then(registration => registration.update())
|
||||||
|
.catch(() => {});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const CACHE_NAME = 'car-monitor-v1';
|
const CACHE_NAME = 'car-monitor-v2';
|
||||||
const CORE_ASSETS = [
|
const CORE_ASSETS = [
|
||||||
'/car/monitor.php',
|
|
||||||
'/car/assets/favicon.svg',
|
'/car/assets/favicon.svg',
|
||||||
'/car/assets/icon-192.png',
|
'/car/assets/icon-192.png',
|
||||||
'/car/assets/icon-512.png',
|
'/car/assets/icon-512.png',
|
||||||
@@ -29,13 +28,18 @@ self.addEventListener('activate', event => {
|
|||||||
self.addEventListener('fetch', event => {
|
self.addEventListener('fetch', event => {
|
||||||
const url = new URL(event.request.url);
|
const url = new URL(event.request.url);
|
||||||
|
|
||||||
if (url.origin !== location.origin || url.searchParams.get('mode') === 'ajax') {
|
if (url.origin !== location.origin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.request.mode === 'navigate' || url.pathname.endsWith('.php') || url.searchParams.has('mode')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
fetch(event.request)
|
fetch(event.request)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
if (!response || !response.ok) return response;
|
||||||
const copy = response.clone();
|
const copy = response.clone();
|
||||||
caches.open(CACHE_NAME).then(cache => cache.put(event.request, copy));
|
caches.open(CACHE_NAME).then(cache => cache.put(event.request, copy));
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
Reference in New Issue
Block a user