caterium-app/public/service-worker.js
pavlov346346-source ce6fa974aa
Caterium v17.6.3 — fix developer gate and SaaS settings
Fix platform developer gate during workspace loading and prevent SaaS click events from reaching Developer Console as DOM buttons. Add v17.6.3 regression tests and PWA cache bump.
2026-09-07 19:31:00 +03:00

33 lines
2.1 KiB
JavaScript

const CACHE='sun-catering-pwa-v68-20260907-v17-6-3-developer-hotfix';
const VERSION='20260907-v17-6-3-developer-hotfix';
const CORE=[
'./','./index.html',
`./core/sun-safe.js?v=${VERSION}`,`./core/performance.js?v=${VERSION}`,`./core/hotfix-v1763.js?v=${VERSION}`,`./core/ops-ux-v1762.js?v=${VERSION}`,`./core/pdf-engine.js?v=${VERSION}`,`./legacy/bootstrap.js?v=${VERSION}`,`./app-runtime.js?v=${VERSION}`,
'./offer-gallery/001.jpg','./offer-gallery/002.jpg',
'./catalog/001.jpg','./catalog/002.jpg','./catalog/003.jpg',
'./sun-logo.png','./caterium-login-logo.png','./pwa-icon-192.png','./pwa-icon-512.png','./manifest.webmanifest',
'./offer-templates/thumb-light.jpg','./offer-templates/thumb-editorial-grid.jpg','./offer-templates/thumb-midnight-glass.jpg','./offer-templates/thumb-emerald-gold.jpg'
];
self.addEventListener('install',event=>{
event.waitUntil(caches.open(CACHE).then(cache=>cache.addAll(CORE)).then(()=>self.skipWaiting()));
});
self.addEventListener('activate',event=>{
event.waitUntil(caches.keys().then(keys=>Promise.all(keys.filter(k=>k.startsWith('sun-catering-pwa-')&&k!==CACHE).map(k=>caches.delete(k)))).then(()=>self.clients.claim()));
});
function cachePut(req,res){
if(res&&res.ok){const clone=res.clone();caches.open(CACHE).then(c=>c.put(req,clone)).catch(()=>{});}return res;
}
function networkFirst(req,fallback){
return fetch(req).then(res=>cachePut(req,res)).catch(()=>caches.match(req).then(hit=>hit||caches.match(fallback||req)));
}
self.addEventListener('fetch',event=>{
const req=event.request;if(req.method!=='GET')return;
const url=new URL(req.url);if(url.pathname.startsWith('/api/'))return;
if(req.mode==='navigate'){
event.respondWith(fetch(req).then(res=>{const clone=res.clone();caches.open(CACHE).then(c=>c.put('./index.html',clone)).catch(()=>{});return res}).catch(()=>caches.match('./index.html')));return;
}
const freshAsset=/\.(?:js|css|webmanifest)$/i.test(url.pathname);
if(freshAsset){event.respondWith(networkFirst(req));return;}
event.respondWith(caches.match(req).then(cached=>cached||fetch(req).then(res=>cachePut(req,res))));
});