feat: add PWA manifest and offline service worker for public pages - #85
Open
ydw1904 wants to merge 1 commit into
Open
feat: add PWA manifest and offline service worker for public pages#85ydw1904 wants to merge 1 commit into
ydw1904 wants to merge 1 commit into
Conversation
Makes the marketing page and interface preview installable and available without a connection. A small build plugin emits sw.js with the hashed asset list injected, mirroring build/sites-vite-plugin.ts rather than adding vite-plugin-pwa and its Workbox tree. Caching: navigations are network-first with cache fallback so the site stays fresh during development, content-hashed assets are cache-first, and Google Fonts are stale-while-revalidate in a separate cache. The licensed control app is deliberately excluded. functions/_middleware.js validates the session cookie on every request to /control-app and /protected-assets/*, so caching either would let a revoked license keep working offline. Those paths are absent from the precache list and are forced to the network by the worker's BYPASS list -- this is a security property, not an optimization. This does not close the "Offline access" roadmap item, which names the control panel specifically. Making that work offline requires deciding how a license validates with no server to check against; opening a separate issue for that. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds the PWA foundation — a web app manifest and a service worker — so the marketing page
(
/) and the interface preview (/demo.html) are installable and load without a connection.Approach
A small build plugin,
build/pwa-vite-plugin.ts, emitssw.jsat build time with the hashedasset list injected. It mirrors the existing
build/sites-vite-plugin.tsrather than pulling invite-plugin-pwaand its Workbox dependency tree, which keeps the repo at zero runtimedependencies and two devDependencies.
Caching strategy:
/assets/*The licensed control app is deliberately excluded
This is a security property, not an optimization — please don't widen the precache list later.
functions/_middleware.jsvalidates theom_license_sessioncookie against Supabase on everyrequest to a protected route, returns
404for/protected-assets/*without a valid session,and sends
Cache-Control: private, no-store. Caching the control app would give a user with anexpired or revoked license permanent offline access to it — exactly what the gate exists to
prevent.
So
/control-app,/protected-assets/*and/controlare absent from the precache list andare additionally forced to the network by the worker's
BYPASSlist.This does not close the "Offline access" roadmap item
That item names the control panel specifically:
Delivering that requires deciding how a license validates with no server to check against, which
is a product decision rather than a build-tooling one. I've opened a separate issue laying out
the options.
Testing
npm run buildpasses; generatedsw.jspassesnode --checkvite preview— worth checking explicitly, sincecache.addAll()rejects atomically and a single 404 would silently break the whole installTo check offline behaviour locally:
npm run build && npx vite preview, then DevTools →Application → Service Workers → tick Offline and reload.