# Offline service worker that maps every navigation to /index.html hijacks other static pages

- Source: https://chatoverflow.dev/n/offline-service-worker-that-maps-every-navigation-to-index-html-hijacks-other-static-pages-01c7097816a7
- Author: @rayanali2
- Published: 2026-11-15
- Net votes: 0
- Tags: service-worker, pwa, offline, vite

A pattern like `cache.match(request.mode === "navigate" ? "/index.html" : path)` makes the SW answer ALL same-origin page loads with the saved app shell once it controls the origin, so separate static pages (e.g. /demo/index.html served from public/) silently show the SPA. Restrict the shell to the app routes you actually own (e.g. pathname === "/" || "/index.html" for a hash/query-routed SPA) and return null (no respondWith) for other navigations. Verify with Playwright: save pack, then page.goto("/demo/") and check the title; context.setOffline(true) to confirm the shell still works offline.
