fix: add one-click PWA cache refresh for login
This commit is contained in:
parent
d9cad541ca
commit
c5d68411ed
52
public/refresh-login-20260912.html
Normal file
52
public/refresh-login-20260912.html
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0">
|
||||||
|
<meta http-equiv="Pragma" content="no-cache">
|
||||||
|
<title>Caterium — обновление</title>
|
||||||
|
<style>
|
||||||
|
html,body{height:100%;margin:0}body{display:grid;place-items:center;background:#f5f0e7;color:#282621;font:16px Arial,sans-serif}.box{width:min(520px,calc(100% - 40px));text-align:center}.mark{width:78px;height:78px;object-fit:contain;margin-bottom:24px}.title{font:500 38px/1.05 Georgia,'Times New Roman',serif;margin:0 0 12px}.text{color:#777168;line-height:1.55}.dot{display:inline-block;width:10px;height:10px;border-radius:50%;background:#e5a313;margin-right:8px;animation:pulse 1s infinite alternate}@keyframes pulse{to{opacity:.25;transform:scale(.8)}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="box">
|
||||||
|
<img class="mark" src="/caterium-mark-light.svg?refresh=20260912-3" alt="Caterium">
|
||||||
|
<h1 class="title">Обновляем Caterium</h1>
|
||||||
|
<p class="text" id="status"><span class="dot"></span>Удаляем старый экран входа и подключаем свежую версию…</p>
|
||||||
|
</main>
|
||||||
|
<script>
|
||||||
|
(async()=>{
|
||||||
|
const status=document.getElementById('status');
|
||||||
|
const stamp='20260912-3-'+Date.now();
|
||||||
|
try{
|
||||||
|
if('serviceWorker' in navigator){
|
||||||
|
const regs=await navigator.serviceWorker.getRegistrations();
|
||||||
|
await Promise.all(regs.map(r=>r.unregister()));
|
||||||
|
}
|
||||||
|
if('caches' in window){
|
||||||
|
const keys=await caches.keys();
|
||||||
|
await Promise.all(keys.map(k=>caches.delete(k)));
|
||||||
|
}
|
||||||
|
if('serviceWorker' in navigator){
|
||||||
|
const reg=await navigator.serviceWorker.register('/service-worker.js?reset='+encodeURIComponent(stamp),{scope:'/'});
|
||||||
|
const worker=reg.installing||reg.waiting||reg.active;
|
||||||
|
if(worker && worker.state!=='activated'){
|
||||||
|
await new Promise(resolve=>{
|
||||||
|
const done=()=>{if(worker.state==='activated'||worker.state==='redundant')resolve()};
|
||||||
|
worker.addEventListener('statechange',done);done();setTimeout(resolve,5000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await navigator.serviceWorker.ready.catch(()=>{});
|
||||||
|
}
|
||||||
|
status.innerHTML='<span class="dot"></span>Готово. Открываем свежий экран входа…';
|
||||||
|
setTimeout(()=>location.replace('/?fresh='+encodeURIComponent(stamp)),350);
|
||||||
|
}catch(err){
|
||||||
|
status.textContent='Кэш очищен частично. Сейчас всё равно откроем приложение заново.';
|
||||||
|
setTimeout(()=>location.replace('/?fresh='+encodeURIComponent(stamp)),800);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user