Introduce the first data layer, move order auto-completion to server cron with legacy/cloud compatibility, clean error telemetry, update PWA/versioning, and add regression coverage.
33 lines
2.4 KiB
JavaScript
33 lines
2.4 KiB
JavaScript
const CACHE='sun-catering-pwa-v75-20260908-v17-7-0-architecture-foundation';
|
|
const VERSION='20260908-v17-7-0-architecture-foundation';
|
|
const CORE=[
|
|
'./','./index.html',
|
|
`./core/sun-safe.js?v=${VERSION}`,`./core/performance.js?v=${VERSION}`,`./core/data-layer-v1770.js?v=${VERSION}`,`./core/server-automation-v1770.js?v=${VERSION}`,`./core/hotfix-v1763.js?v=${VERSION}`,`./core/ops-ux-v1762.js?v=${VERSION}`,`./core/ux-fixes-v1764.js?v=${VERSION}`,`./core/pdf-engine.js?v=${VERSION}`,`./core/classic-offer-pdf-v1767.js?v=${VERSION}`,`./core/developer-console-v1768.js?v=${VERSION}`,`./core/offer-workspace-v1769.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))));
|
|
});
|