Compare commits

..

2 Commits

Author SHA1 Message Date
79fa7984a1 feat(sw): auto-reload page when service worker updates
Add updatefound listener in catalog.html that reloads the page
automatically when a new service worker is activated. This ensures
users get the latest HTML and JS without manual hard refresh.
2026-05-14 22:26:42 +00:00
30abecc07d fix(sw): v6 with network-first HTML strategy
- Bump cache to nexus-pos-v6 to force invalidation
- HTML pages now use network-first instead of cache-first
  This ensures users always get the latest HTML with correct
  JS/CSS references (?v=3) instead of stale cached HTML
- Remove HTML pages from APP_SHELL precache (only static assets)
- Keep cache-first for JS/CSS/images
2026-05-14 22:26:27 +00:00
2 changed files with 19 additions and 16 deletions

View File

@@ -1,20 +1,10 @@
// /home/Autopartes/pos/static/pwa/sw.js
// Nexus POS — Service Worker v5
// Nexus POS — Service Worker v6
// Self-contained vanilla JS. No external imports.
const CACHE_NAME = 'nexus-pos-v5';
const CACHE_NAME = 'nexus-pos-v6';
const APP_SHELL = [
'/pos/login',
'/pos/sale',
'/pos/catalog',
'/pos/inventory',
'/pos/customers',
'/pos/invoicing',
'/pos/accounting',
'/pos/dashboard',
'/pos/config',
'/pos/reports',
'/pos/static/css/tokens.css',
'/pos/static/css/common.css',
'/pos/static/js/app-init.js',
@@ -132,8 +122,8 @@ self.addEventListener('fetch', function (event) {
return;
}
// Don't cache login page
if (url.pathname === '/pos/login' || url.pathname === '/pos/login/') {
// HTML pages -> network-first (always fresh)
if (req.headers.get('accept') && req.headers.get('accept').indexOf('text/html') !== -1) {
event.respondWith(networkFirst(req));
return;
}
@@ -181,7 +171,7 @@ self.addEventListener('fetch', function (event) {
return;
}
// Everything else -> cache-first
// Everything else (JS, CSS, images) -> cache-first
event.respondWith(cacheFirst(req));
});

View File

@@ -293,7 +293,20 @@
<script src="/pos/static/js/chat.js" defer></script>
<script src="/pos/static/js/sync-engine.js" defer></script>
<script src="/pos/static/js/onboarding.js" defer></script>
<script>if('serviceWorker' in navigator){navigator.serviceWorker.register('/pos/sw.js',{scope:'/pos/'});}</script>
<script>
if('serviceWorker' in navigator){
navigator.serviceWorker.register('/pos/sw.js',{scope:'/pos/'}).then(function(reg){
reg.addEventListener('updatefound', function(){
var newWorker = reg.installing;
newWorker.addEventListener('statechange', function(){
if(newWorker.state === 'activated'){
window.location.reload();
}
});
});
});
}
</script>
<script src="/pos/static/js/pwa-install.js" defer></script>
<script src="/pos/static/js/brand-catalog.js?v=3" defer></script>
</body>