Making a booking page installable: tenant-aware PWA with vite-plugin-pwa
A PWA is usually explained with one manifest and one service worker. That's fine until you serve many tenants from one installation — then every tenant needs its own app identity, its own icon label, its own start URL, and none of them should collide. This post covers the parts that were not obvious: a per-tenant manifest, the id field that prevents duplicate home-screen icons, an update flow…
Progressive Web Apps (PWAs) typically require a single manifest and service worker. However, when serving multiple tenants from one installation, each tenant needs its own app identity, icon, and start URL to avoid conflicts. This article explores the nuances of implementing per-tenant PWAs using Vite 6 and vite-plugin-pwa, along with Workbox generateSW.
To set up Vite 6 with vite-plugin-pwa and Workbox generateSW, configure the manifest generation at runtime using the prompt registration type. This approach allows the service worker to install and wait before updating, preventing conflicts between tenants.
Each tenant is identified by a unique slug, which is used to generate a per-tenant manifest. The manifest includes essential properties such as id, name, short_name, start_url, scope, display, orientation, background_color, theme_color, and icons. The manifest response is set to no-store to ensure it is always fresh and avoids caching stale data.
An important consideration is the id field in the manifest. Chrome identifies an installed PWA by its manifest id, so providing a stable, non-changing id per tenant prevents multiple installations with the same shop appearing on the home screen. Changing the id even slightly can result in duplicate icons and entries, making it crucial to treat it like a database key.
The update flow for PWA installations with registerType: prompt ensures that form data is preserved. When a new version is available, a banner prompts the user to reload the page, allowing the new service worker to take over. The controllerchange event is listened for, triggering a reload when the waiting worker skips its waiting phase. This update mechanism prevents the partial filling of booking forms from being lost.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.