Documentation Index
Fetch the complete documentation index at: https://mintlify.com/facebook/docusaurus/llms.txt
Use this file to discover all available pages before exploring further.
@docusaurus/plugin-pwa adds Progressive Web App (PWA) support to your Docusaurus site using Workbox. It generates a service worker in production builds that precaches your site’s assets, enabling offline access and installability. The plugin requires no extra configuration when your site already has a valid web app manifest — just install, point to your manifest, and configure the <head> tags.
Installation
npm2yarn
Quick start
- Create a PWA manifest at
static/manifest.json. - Register the plugin in
docusaurus.config.jswith the minimum requiredpwaHeadentries.
docusaurus.config.js
Configuration options
| Option | Type | Default | Description |
|---|---|---|---|
debug | boolean | false | Enable debug mode: verbose Workbox logs, unminified service worker output, and source maps. |
offlineModeActivationStrategies | OfflineStrategy[] | ['appInstalled', 'queryString', 'standalone'] | Conditions that activate offline mode (serving cached responses). See strategies below. |
injectManifestConfig | InjectManifestOptions | {} | Workbox injectManifest() options controlling which assets are precached. |
pwaHead | PwaHeadTag[] | [] | Array of <head> tag objects to inject for PWA compliance. |
swCustom | string | undefined | undefined | Path to a custom service worker module with additional Workbox rules. |
swRegister | string | false | 'docusaurus-plugin-pwa/src/registerSW.js' | Entry module used to register the service worker before the app boots. Set false to disable registration. |
Offline mode activation strategies
TheofflineModeActivationStrategies option accepts an array of strategy names. Offline mode is enabled when any of the configured strategies matches:
| Strategy | Activation condition |
|---|---|
appInstalled | The user has installed the site as an app (uses the deprecated appinstalled event — not 100% reliable). |
standalone | The app is running in standalone mode (i.e. launched from the home screen after install). Recommended fallback. |
queryString | The URL contains ?offlineMode=true. Useful for testing PWA behavior without installing. |
mobile | The viewport width is ≤ 996px. |
saveData | navigator.connection.saveData === true (user has enabled data-saver mode). |
always | All users, unconditionally. |
pwaHead — injecting PWA <head> tags
pwaHead accepts an array of objects, each with a tagName key plus any number of additional attribute key-value pairs. These are injected into <head> on every page.
For full PWA compliance (installable on iOS, Android, Windows, and Chrome), include at minimum:
injectManifestConfig — controlling precaching
Workbox’s injectManifest() is used under the hood. Pass any supported InjectManifestOptions to control which files are precached:
docusaurus.config.js
Docusaurus already adds all HTML, JS, CSS, and image assets to the precache manifest by default. Use
globPatterns to add extra file types.swCustom — extending the service worker
Point swCustom at a JavaScript module that exports a default function. The module is transpiled, so modern ES2020+ syntax is supported. Use the full Workbox API to add custom caching strategies:
src/sw-custom.js
docusaurus.config.js
manifest.json example
Place your manifest at static/manifest.json so it is served at /manifest.json:
static/manifest.json
Offline mode behavior
When offline mode is active, the service worker serves precached responses for all navigations. When a new build is deployed:- The new service worker installs and enters a waiting state.
- A reload popup (
@theme/PwaReloadPopup) appears in the bottom right corner. - When the user clicks Refresh, the new service worker activates and the page reloads.
@theme/PwaReloadPopup. The component receives an onReload callback prop that triggers activation of the waiting worker.