docs/features/pwa.md
Slides are often presented on an unfamiliar or locked-down machine, over a flaky or absent network. With the opt-in pwa option, slidev build generates a service worker (powered by vite-plugin-pwa and Workbox) that precaches every deck asset — JavaScript, CSS, and HTML plus all images, video, and audio — so once the served deck has loaded a first time, it runs entirely from the cache with no per-slide asset fetching mid-talk.
Enable it in the headmatter of your first slide:
---
pwa: true
---
The pwa option can be a boolean or a string to control when the service worker is active:
false (default) — no service worker.true — enabled in both dev and build.'build' — enabled in the built output only.'dev' — enabled in the dev server only.Since precaching every asset is heavy, pwa is off by default and should be enabled deliberately — most useful together with slidev build for a self-hosted deck you want to work offline.
PWA support is powered by vite-plugin-pwa, which ships as an optional peer dependency. It is not installed by default, so decks that don't opt into pwa never download it.
The first time you enable pwa, the Slidev CLI detects that the package is missing and prompts you to install it:
? The "pwa" option requires the "vite-plugin-pwa" package, which is not installed
in your project. Install it now? › (Y/n)
Confirm the prompt and Slidev installs it for you with your project's package manager (or globally, when Slidev itself is installed globally). In a non-interactive environment (such as CI) the prompt can't be shown, so install it ahead of time instead:
npm i -D vite-plugin-pwa
When you serve the built deck, the service worker downloads and caches all deck assets in the background. A small indicator in the bottom-right corner shows Caching for offline… while precaching is in progress, then briefly shows Ready offline once it completes. After that, disconnecting the network and reloading serves the whole deck — HTML, images, and video — from the cache.
The plugin is a complete no-op when pwa is disabled, and the client registration and indicator are tree-shaken out of the bundle, so there is no runtime cost unless you opt in.
favicon may be a URL), so the generated web app manifest intentionally ships no icons. It remains a valid manifest without them.maximumFileSizeToCacheInBytes is raised to 100 MB and the precache glob covers common image, video, and audio extensions, so large media files are not silently skipped.