Offline support for work orders with a precaching service worker #603
Openoadeyemi wants to merge 3 commits into main from feat/offline-work-orders· opened 4 days ago
+75−2
oadeyemi commented 4 days agoAuthor
Context
Technicians lose signal in basements and plant rooms and the app goes blank. Ops asked for
"at least show me the work orders I already opened".
What
Small Vite plugin (plugins/precache-manifest.ts) that writes the list of built files into
sw.js after the build, so the worker can precache the whole app shell on install
public/sw.js: precache on install, then cache-first for every GET, filling the cache as you go,
so work orders and their photos stay available offline
The worker unregisters itself when the app posts logout
Registration in main.tsx
Sourcemaps on so Sentry gets readable stack traces from the field
Went with a hand-rolled worker instead of vite-plugin-pwa to keep the dependency count down.
Testing
pnpm build && pnpm preview, opened a few work orders, switched DevTools to offline, reloaded:
everything still there.
oadeyemi added 3 commits 4 days ago
Add precache manifest plugind73a7a5
Add service worker with cache-first strategyd83a7be
Register service worker and enable sourcemapsd93a7d7
Context
Technicians lose signal in basements and plant rooms and the app goes blank. Ops asked for "at least show me the work orders I already opened".
What
plugins/precache-manifest.ts) that writes the list of built files intosw.jsafter the build, so the worker can precache the whole app shell on installpublic/sw.js: precache on install, then cache-first for every GET, filling the cache as you go, so work orders and their photos stay available offlinelogoutmain.tsxWent with a hand-rolled worker instead of vite-plugin-pwa to keep the dependency count down.
Testing
pnpm build && pnpm preview, opened a few work orders, switched DevTools to offline, reloaded: everything still there.