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.
This commit is contained in:
2026-05-14 22:26:42 +00:00
parent 30abecc07d
commit 79fa7984a1

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>