서비스워커 자산 캐시 제거
This commit is contained in:
@@ -44,7 +44,7 @@ Financial은 개인 금융 데이터를 서버 렌더링 PHP 화면에서 관리
|
||||
- `public/assets/asset-reload.js`: 열린 브라우저에서 파일 묶음 hash가 달라졌는지 확인하고 새로 여는 스크립트
|
||||
- `public/assets/pwa.js`, `public/sw.js`: PWA 동작
|
||||
|
||||
`asset-version.php`는 `app`의 PHP 파일과 `public`의 PHP/HTML/JS/CSS/manifest/icon 파일을 읽어 크기, 수정 시각, sha256 hash를 묶은 버전을 만듭니다. 공통 헤더, 로그인, 회원가입 화면에서 `asset-reload.js`를 불러오며, 파일 묶음 hash가 달라지면 Cache Storage를 비우고 현재 화면을 다시 엽니다. 현재 URL의 `assetReload` 토큰이 최신 파일 묶음 hash와 다르면 첫 진입도 토큰을 붙인 URL로 다시 열어 낡은 JS/CSS가 먼저 실행되는 상황을 줄입니다. 모바일/삼성 브라우저 호환을 위해 화면 복귀, 온라인 복귀, 터치/클릭 복귀 이벤트도 확인하고, Web Storage 실패 시 쿠키 fallback으로 이전 버전을 비교합니다.
|
||||
`asset-version.php`는 `app`의 PHP 파일과 `public`의 PHP/HTML/JS/CSS/manifest/icon 파일을 읽어 크기, 수정 시각, sha256 hash를 묶은 버전을 만듭니다. 공통 헤더, 로그인, 회원가입 화면에서 `asset-reload.js`를 불러오며, 파일 묶음 hash가 달라지면 Cache Storage를 비우고 현재 화면을 다시 엽니다. 현재 URL의 `assetReload` 토큰이 최신 파일 묶음 hash와 다르면 첫 진입도 토큰을 붙인 URL로 다시 열어 낡은 JS/CSS가 먼저 실행되는 상황을 줄입니다. 모바일/삼성 브라우저 호환을 위해 화면 복귀, 온라인 복귀, 터치/클릭 복귀 이벤트도 확인하고, Web Storage 실패 시 쿠키 fallback으로 이전 버전을 비교합니다. 화면 PHP는 `no-store` 헤더를 내려 문서 자체가 오래 남지 않게 하고, service worker는 오프라인 안내 화면만 남긴 뒤 앱 파일과 HTML은 네트워크에서 다시 받습니다.
|
||||
|
||||
## 데이터/저장소
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
<?php require_once __DIR__ . '/../lib/helpers.php'; ?>
|
||||
<?php
|
||||
require_once __DIR__ . '/../lib/helpers.php';
|
||||
if (function_exists('send_private_no_store_headers')) {
|
||||
send_private_no_store_headers();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
@@ -37,7 +42,7 @@
|
||||
|
||||
<link href="/assets/vendor/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/assets/app.css" rel="stylesheet">
|
||||
<script src="/assets/asset-reload.js?v=20260721_autotoken1" data-service="financial" defer></script>
|
||||
<script src="/assets/asset-reload.js?v=20260721_nocache1" data-service="financial" defer></script>
|
||||
<script src="https://chaegeon.com/log/bancheck.min.js?_=<?php echo time(); ?>"></script>
|
||||
<script src="/assets/vendor/chart.umd.js"></script>
|
||||
</head>
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
}
|
||||
|
||||
window.addEventListener('load', function () {
|
||||
navigator.serviceWorker.register('/sw.js').catch(function () {});
|
||||
navigator.serviceWorker.register('/sw.js?v=20260721_nocache1').then(function (registration) {
|
||||
if (registration && typeof registration.update === 'function') registration.update();
|
||||
}).catch(function () {});
|
||||
});
|
||||
})();
|
||||
|
||||
+3
-1
@@ -3,6 +3,8 @@ require_once __DIR__ . '/../app/lib/db.php';
|
||||
require_once __DIR__ . '/../app/lib/auth.php';
|
||||
require_once __DIR__ . '/../app/lib/helpers.php';
|
||||
|
||||
send_private_no_store_headers();
|
||||
|
||||
if (!empty($_SESSION['user_id'])) {
|
||||
header('Location: /dashboard.php');
|
||||
exit;
|
||||
@@ -78,7 +80,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
|
||||
<link href="/assets/vendor/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/assets/app.css" rel="stylesheet">
|
||||
<script src="/assets/asset-reload.js?v=20260721_autotoken1" data-service="financial" defer></script>
|
||||
<script src="/assets/asset-reload.js?v=20260721_nocache1" data-service="financial" defer></script>
|
||||
<script src="https://chaegeon.com/log/bancheck.min.js?_=<?php echo time(); ?>"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
+3
-1
@@ -3,6 +3,8 @@ require_once __DIR__ . '/../app/lib/db.php';
|
||||
require_once __DIR__ . '/../app/lib/auth.php';
|
||||
require_once __DIR__ . '/../app/lib/helpers.php';
|
||||
|
||||
send_private_no_store_headers();
|
||||
|
||||
if (!empty($_SESSION['user_id'])) {
|
||||
header('Location: /dashboard.php');
|
||||
exit;
|
||||
@@ -87,7 +89,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<link rel="manifest" href="/manifest.webmanifest">
|
||||
<link href="/assets/vendor/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/assets/app.css" rel="stylesheet">
|
||||
<script src="/assets/asset-reload.js?v=20260721_autotoken1" data-service="financial" defer></script>
|
||||
<script src="/assets/asset-reload.js?v=20260721_nocache1" data-service="financial" defer></script>
|
||||
<script src="https://chaegeon.com/log/bancheck.min.js?_=<?php echo time(); ?>"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
+5
-16
@@ -1,13 +1,6 @@
|
||||
const CACHE_NAME = 'financial-static-v1';
|
||||
const CACHE_NAME = 'financial-offline-v20260721-nocache1';
|
||||
const STATIC_ASSETS = [
|
||||
'/offline.html',
|
||||
'/assets/vendor/bootstrap.min.css',
|
||||
'/assets/vendor/bootstrap.bundle.min.js',
|
||||
'/assets/vendor/chart.umd.js',
|
||||
'/assets/app.css',
|
||||
'/assets/pwa.js',
|
||||
'/favicon.png?v=2',
|
||||
'/manifest.webmanifest'
|
||||
'/offline.html'
|
||||
];
|
||||
|
||||
self.addEventListener('install', event => {
|
||||
@@ -45,16 +38,12 @@ self.addEventListener('fetch', event => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.pathname.startsWith('/assets/vendor/') || url.pathname === '/assets/app.css' || url.pathname === '/assets/pwa.js' || url.pathname === '/manifest.webmanifest' || url.pathname === '/favicon.png') {
|
||||
if (request.mode === 'navigate') {
|
||||
event.respondWith(
|
||||
caches.match(request).then(cached => cached || fetch(request))
|
||||
fetch(request, { cache: 'no-store' }).catch(() => caches.match('/offline.html'))
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.mode === 'navigate') {
|
||||
event.respondWith(
|
||||
fetch(request).catch(() => caches.match('/offline.html'))
|
||||
);
|
||||
}
|
||||
event.respondWith(fetch(request, { cache: 'no-store' }));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user