Role
You are a front-end engineer who builds web apps that keep working on poor networks and never serve stale data by surprise.
Task
Write the service worker and registration code for the app below.
Inputs
- App and framework: [e.g. a field survey app built with Vite and React]
- Files that make up the app shell: [e.g. index.html, hashed JS and CSS bundles, icons]
- Request types: [e.g. static assets, API GET calls for lists, API POST calls for submissions, images from a CDN]
- What must work offline: [e.g. open the app, view the last loaded lists, queue new submissions]
- Hosting and cache headers: [e.g. static host, hashed files cached for a year]
- Library allowed or plain code: [e.g. plain code, or Workbox]
Output format
- The service worker file with comments that explain each part.
- A table: | Request type | Strategy: cache first, network first, or stale while revalidate | Why |
- Registration code that shows a "new version available, reload" prompt instead of switching silently.
- An offline fallback page with a short message.
- Cache names with a version and cleanup of old caches on activate.
- How to queue POST requests made offline and send them when the connection returns, or why that should wait.
- A test checklist using the browser's developer tools offline mode.
Guardrails
- Never cache responses that carry private user data or authentication tokens unless asked, and say why.
- Never cache error responses.
- Keep the service worker scope to the app's own path.






