// Tavolo service worker: installability only, no offline caching. // // The app is a thin client for a live game server: state arrives over // /api and /ws and is never safe to replay from a cache, and a new build // changes the hashed asset names, so stale cached files would break the // app until the cache expired. The worker therefore only performs the // passthrough fetch below — enough for the browser to treat the app as // installable — and leaves every request's caching to the network stack. self.addEventListener("install", () => { // A new worker takes over on the next reload instead of waiting for // every tab of the old version to close. self.skipWaiting(); }); self.addEventListener("activate", (event) => { event.waitUntil(self.clients.claim()); }); self.addEventListener("fetch", (event) => { const url = new URL(event.request.url); // Let the browser handle other origins and the live endpoints directly // (respondWith would only add a hop; /auth navigations must be allowed // to follow their redirects untouched). if ( url.origin !== self.location.origin || url.pathname.startsWith("/api/") || url.pathname.startsWith("/auth/") || url.pathname.startsWith("/ws") ) { return; } event.respondWith(fetch(event.request)); });