👑
Crown

Zero-Config PWA

Crown makes it incredibly simple to turn your application into a Progressive Web App (PWA). With just a single flag, your app can work offline and sync data in the background.

The Problem with PWAs

Traditionally, building a PWA requires manual setup of Service Workers, configuring caching strategies, and writing complex synchronization logic to handle offline requests. Crown automates all of this.

Enabling PWA Support

To enable PWA support, simply set "pwa": true in your crown.json configuration file:

{
  "port": 5000,
  "tailwind": true,
  "pwa": true
}

Once enabled, run crown dev or crown build. Crown will automatically generate a manifest.json and a sw.js (Service Worker) in your public/ directory.

Offline Request Queuing & Background Sync

Crown's Service Worker goes beyond simple caching. It intelligently intercepts API requests when the user is offline:

  • GET Requests: Cached automatically using a Network-First strategy. If offline, the last cached version is served.
  • POST/PUT/DELETE Requests: If offline, these requests are safely stored in the browser's IndexedDB queue.
  • HTMX Integration: If an HTMX request is queued while offline, Crown returns a special HTML snippet alerting the user that the action was saved locally.
  • Background Sync: The moment the device regains connectivity, the Service Worker automatically flushes the queue, replaying the stored requests to the server in order.

Disabling PWA

If you decide to turn off PWA support, simply change the setting to "pwa": false in crown.json. Crown will automatically inject a script into your pages that securely unregisters any existing Service Workers from users' browsers, preventing stale caches or "zombie" apps.