wowprompt

Offline support with a service worker for a progressive web app

Writes a service worker and the registration code that let a web app open and stay useful without a connection: which files to precache, a caching strategy for each kind of request, an offline fallback page, safe updates and a way to clear old caches. Use it for field apps, catalogues, menus and tools used on patchy mobile networks.

A service worker file with precaching, per-route caching strategies, an offline fallback and cache versioning, plus registration code and a test checklist
The output this prompt produced, unedited.

The prompt

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

  1. The service worker file with comments that explain each part.
  2. A table: | Request type | Strategy: cache first, network first, or stale while revalidate | Why |
  3. Registration code that shows a "new version available, reload" prompt instead of switching silently.
  4. An offline fallback page with a short message.
  5. Cache names with a version and cleanup of old caches on activate.
  6. How to queue POST requests made offline and send them when the connection returns, or why that should wait.
  7. 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.
service workerprogressive web appoffline web apppwa cachingcache strategyoffline fallback page

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity