PWA and Offline Support — Reading This Site Without a Network
This site is built as a PWA (Progressive Web App) so that every document remains readable on a plane or anywhere without connectivity. This article covers the fundamentals of PWA and the configuration, design decisions, and caveats from applying it to this site.
What is a PWA?
A PWA makes a website behave like an installable app that also works offline. It requires no store review or native implementation and is built entirely with standard web technologies (HTML / CSS / JavaScript).
Three requirements are typically cited for calling a site a PWA.
| Requirement | Role | Implementation on this site |
|---|---|---|
| HTTPS | Service workers only run in secure contexts | Served over HTTPS by Cloudflare Pages |
| Web App Manifest | Defines the app name, icons, start URL, and display mode | static/manifest.json |
| Service Worker | A proxy between the network and the page; owns caching and offline responses | Generated by @docusaurus/plugin-pwa |
Comparison with a regular website and a native app
| Aspect | Regular website | PWA | Native app |
|---|---|---|---|
| Installation | None (just open the URL) | Add to home screen from the browser | Install from a store |
| Offline | Not possible (relies on browser cache) | Possible via service worker | Possible |
| Updates | Reflected on reload | Service worker updates on next launch | Through the store |
| Distribution | URL | URL (no store) | Store review |
| Device capabilities | Limited | Progressively available (notifications, camera, etc.; see the next section) | Full |
What a PWA cannot do — where a native app is required
As the comparison above shows, PWA capabilities keep expanding, and a typical app made of screens, forms, lists, maps, payments, and notifications is now achievable with a PWA. Not everything is possible, however. This section catalogs what a PWA cannot do, or can only do with significant constraints.
What PWAs can do as of 2026
As a baseline, today's PWAs can do all of the following with standard web APIs:
- Installation and standalone launch (added to the home screen / app list)
- Offline operation and caching via service workers (the subject of this article)
- Web Push notifications and app icon badges (on iOS 16.4+, for home screen web apps only)
- Camera, microphone, and foreground geolocation
- Sign-in with biometrics via WebAuthn / passkeys
- OS share sheet access via the Web Share API
- Web payments (Payment Request API; Apple Pay / Google Pay on the web)
- Reading and writing files the user selects (File System Access API, Chromium-centric)
- Rendering and compute via WebGL / WebGPU / WebAssembly
In other words, apps where the user is in front of the screen interacting with a server can be built at near-native quality. The following categories, however, remain out of reach.
1. Background execution
This is where a PWA falls furthest behind native. A service worker is not a resident process: it wakes for events and terminates shortly after, so you cannot rely on continuous processing while the app is closed.
| Goal | Status | Notes |
|---|---|---|
| Periodic data fetching while the app is closed | Partial | Periodic Background Sync (Chromium only). Requires installation and engagement; at best every 12 hours (24–36 hours for less-used apps), and each run is limited to minutes |
| Automatic retry of queued uploads | Partial | Background Sync / Background Fetch (Chromium only). Not available in Safari / Firefox; you must retry on next launch |
| Background location tracking / geofencing | No | No web API exists (foreground geolocation only) |
| Background BLE scanning / beacon detection | No | Web Bluetooth works only in the foreground |
| Long-running uploads / downloads | Partial | Background Fetch (Chromium only). On Safari the page must stay open |
| Launch at OS login | Partial | User-configurable on Chromium desktop (apps cannot control it) |
A service worker can wake briefly for notifications or periodic sync events, but it is not suited to continuous monitoring or timers. If running in the background is a requirement, you need native code.
2. Push notification constraints
- On iOS, push works only in web apps added to the Home Screen. In a Safari tab,
Notificationdoes not exist at all, and permission can only be requested in response to a user gesture. - Every browser requires a user-visible notification. Silent push (receiving data in the background with no notification) is not possible.
- iOS notifications are limited to title, body, and badge; action buttons and images are not available (Android Chrome supports them).
- There is no API for scheduling local notifications at a specific time (a push from a server is required).
- On iOS, tapping a notification opens the installed web app, but links in email or other apps open in Safari (Android Chrome opens in-scope links in the installed app).
3. Device hardware access
| API / capability | What it enables | Support |
|---|---|---|
| Web Bluetooth | Communication with BLE (GATT) devices | Chromium (desktop and Android) only; not Safari or Firefox |
| Web NFC | Reading and writing NFC tags | Chrome for Android only; no card emulation (payments) |
| WebUSB | Low-level USB device communication | Chromium only; devices not claimed by an OS driver |
| Web Serial / WebHID | Serial and HID device communication | Mostly Chromium desktop; not Safari or Firefox |
| Camera / microphone | Capture and recording | Yes; no RAW capture or manual exposure control |
| Geolocation | Current position | Yes (foreground only); no background tracking |
| Biometrics | Biometric sign-in | Yes (WebAuthn / passkeys) |
| Vibration | Vibration | Chrome for Android yes; iOS has no Vibration API |
| AR | AR via WebXR | Chromium on Android, Safari on visionOS, etc.; not Safari on iPhone / iPad |
Camera, location, and microphone are available to PWAs for general audiences. Business apps that need peripherals (BLE, NFC, USB) require native code if iOS users are in scope.
4. OS integration
| Capability | Status | Notes |
|---|---|---|
| Home screen / lock screen widgets | No | WidgetKit and Android widgets are native-only |
| Live Activities / Dynamic Island | No | ActivityKit is native-only |
| Watch apps (Apple Watch / Wear OS) | No | Not available on the web |
| Car (CarPlay / Android Auto) | No | Not available on the web |
| Voice assistant integration (Siri Shortcuts, etc.) | No | — |
| Share sheet registration (share target) | Partial | Chromium (Android and desktop) only; requires installation |
| File associations (open by double-click) | Partial | Chromium desktop only |
| Custom URL scheme registration | Partial | Chromium desktop only |
| Tray / menu bar icon | No | — |
| Global hotkeys | No | — |
| Contacts, calendar, health data | No | No web APIs (contact picking only via Contact Picker on Chrome for Android) |
| Phone / SMS / VoIP incoming-call UI | No | No CallKit / ConnectionService equivalent |
5. Data persistence
- Treat browser storage (Cache Storage / IndexedDB) as a cache that can disappear.
- When storage is under pressure, browsers may evict data from the least recently used origins.
- In Safari, storage used in regular tabs is deleted after seven days of Safari use without interaction, but installed web apps are exempt (one of the incentives to install).
navigator.storage.persist()requests persistence but does not guarantee it. Safari (17+) decides heuristically without a prompt and favors installed web apps.- Deleting the app (removing it from the home screen, clearing site data) deletes its data. There is also no guarantee it is included in OS backups.
- A PWA cannot read arbitrary files on the device, only files the user selects (File System Access API, Chromium-centric).
You can build an offline cache with a PWA, but you cannot guarantee that on-device data survives. Design so that data can be restored from the server, treating the server as the source of truth.
6. Distribution, stores, and monetization
| Item | Status | Notes |
|---|---|---|
| iOS App Store distribution | No | Pure PWAs are not accepted; wrappers can be rejected as "minimum functionality" (Guideline 4.2) |
| Google Play | Partial | Possible by wrapping in a Trusted Web Activity (TWA) |
| Microsoft Store | Yes | PWAs can be submitted as-is |
| Store features (search discovery, reviews, staged rollout, TestFlight, etc.) | No | — |
| In-app purchases (StoreKit / Play Billing) | No | Web payments are possible, but store billing, subscription management, and refunds are not |
| MDM / enterprise distribution | No | Desktop Chrome / Edge management policies can distribute web apps as an exception |
| Automatic install prompt | Partial | Android supports a custom install button via beforeinstallprompt; iOS does not (manual Share menu only). Since iOS 26, "Open as Web App" is the default, so any site can be used as a web app even without a manifest |
7. Performance and native SDKs
- Platform SDKs such as HealthKit, HomeKit, ARKit, and Core ML are inaccessible. You are limited to what approximate web APIs (WebXR, WebGPU, and so on) can do.
- You cannot embed native code (Swift / Kotlin / C++); you are limited to what WebAssembly can substitute.
- There is no direct control over threads, GPU, or memory (approximated by Web Workers / WebGPU).
- Games, video editing, 3D CAD, and other compute- and graphics-heavy apps favor native.
- There is no OS-level observability such as crash reports or ANR monitoring.
When you actually need a native app
| Requirement | Suitable technology |
|---|---|
| Content and documents (a reading site like this one) | PWA |
| Forms, booking, e-commerce, internal tools | PWA |
| Notification-centric apps (if requiring installation on iOS is acceptable) | PWA |
| Foreground camera / location use | PWA |
| Background location, BLE, geofencing | Native |
| Peripherals (BLE / NFC / USB) on iOS | Native |
| Widgets, watch, car, health | Native |
| App Store distribution and store billing | Native (or a wrapper) |
| High-end 3D games, video editing | Native |
Practical options when native is required:
- Android only: a TWA (Bubblewrap / PWABuilder) to ship on Google Play
- Cross-platform: wrap the web assets with something like Capacitor and bridge to native APIs
- iOS store distribution: a PWA plus a thin native shell (WebView wrapper). Note that "a repackaged website" risks rejection under App Store Guideline 4.2
Impact on this site
This site is a reading site (content site), so almost none of the constraints above apply. It uses no notifications, location, peripherals, or payments, and "readable offline" plus "searchable offline" are exactly what PWAs do best. Even if native features were needed in the future, content delivery could stay on the web with a native shell layered on top.
How offline browsing works
A service worker (SW) is a proxy that sits between the page and the network. This site precaches the entire static site into Cache Storage during the SW install event and serves subsequent requests from that cache.
The advantage of precaching is that you are not limited to pages you happened to visit: the whole site is stored at install time. The trade-off is a sizeable download on first use (see below).
Implementation on this site
Files changed
| File | Purpose |
|---|---|
package.json | Adds @docusaurus/plugin-pwa |
docusaurus.config.ts | Plugin options (precache conditions, size limit, <head> tags) |
static/manifest.json | Web App Manifest |
static/img/pwa-icon-192.png / pwa-icon-512.png | Icons for installation |
src/theme/PwaReloadPopup/index.tsx | Swizzled update popup: applies updates automatically |
1. Installing the plugin
The official @docusaurus/plugin-pwa generates a service worker with Workbox.
npm install --save @docusaurus/plugin-pwa
Configuration excerpt from docusaurus.config.ts:
plugins: [
[
'@docusaurus/plugin-pwa',
{
offlineModeActivationStrategies: [
'appInstalled',
'standalone',
'queryString',
],
injectManifestConfig: {
// Precache the search index (search-index.json) as well
maximumFileSizeToCacheInBytes: 50 * 1024 * 1024,
},
pwaHead: [
{tagName: 'link', rel: 'manifest', href: '/manifest.json'},
{tagName: 'meta', name: 'theme-color', content: '#1976d2'},
{tagName: 'meta', name: 'mobile-web-app-capable', content: 'yes'},
{
tagName: 'link',
rel: 'apple-touch-icon',
href: '/img/pwa-icon-192.png',
},
],
},
],
],
docusaurus start (the dev server) does not generate a service worker. Only the output of npm run build (or npm run build:parallel) includes sw.js.
2. Web App Manifest
Add static/manifest.json.
{
"name": "Web Development Knowledge Base",
"short_name": "WebDevKB",
"start_url": "./",
"scope": "./",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#1976d2",
"icons": [
{"src": "img/pwa-icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any"},
{"src": "img/pwa-icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"}
]
}
Design notes:
- Relative
start_url/scope(./): this site serves ja at/and en at/en/, and the manifest is emitted as both/manifest.jsonand/en/manifest.json. Relative values make the start URL resolve to the installed locale's root. - Both 192px and 512px icons: Chrome requires these sizes for installability.
purpose: maskable: Android adaptive icons crop the image, so the icon keeps padding around the logo.
The pwaHead option injects the manifest link and theme color into <head>.
3. When precaching is enabled
offlineModeActivationStrategies decides when precaching is turned on.
| Strategy | Condition |
|---|---|
appInstalled | The app is installed (appinstalled event / getInstalledRelatedApps()) |
standalone | Launched from the home screen icon (display-mode: standalone) |
queryString | Accessed with ?offlineMode=true |
mobile | Viewport width of 996px or less (not used here) |
saveData | Data Saver is enabled |
always | Always on |
mobile is deliberately excluded: precaching is about 60MB per locale, and automatically downloading that for every mobile visitor would be inappropriate. appInstalled and standalone target only people who installed the app, while queryString is kept for testing.
offlineMode only controls whether precaching runs. The service worker itself is registered on the first visit, which makes the site installable together with the manifest.
4. What gets precached, and how large it is
By default the Docusaurus PWA plugin precaches:
**/*.{js,json,css,html}**/*.{png,jpg,jpeg,gif,svg,ico}**/*.{woff,woff2,eot,ttf,otf}
Measured on this site:
| Locale | Service worker | Entries | Total size |
|---|---|---|---|
| ja | /sw.js | 1734 | ~63MB |
| en | /en/sw.js | 1716 | ~55MB |
Why maximumFileSizeToCacheInBytes is raised to 50MB: the local search index search-index.json is 18.6MB (ja) and 13.3MB (en). Workbox's default 2MiB limit would exclude it; online search would still work, but offline search would fail.
5. Offline search
Search on this site is generated at build time by @easyops-cn/docusaurus-search-local and does not depend on an external service.
- The build emits
search-index.json - The client fetches it with a cache-busting query, e.g.
search-index.json?_=<hash> - The Docusaurus service worker ignores query strings when looking up cache keys
As a result, precaching search-index.json makes search work in airplane mode.
6. One service worker per locale
The ja and en builds register service workers with different scopes:
- ja:
/sw.js(scope/) - en:
/en/sw.js(scope/en/)
The root service worker can also control /en/ pages, but its precache contains no en URLs, so those requests fall back to the network. To read the English site offline, open /en/ while online first so the en service worker is installed.
7. URL and cache key resolution
For a URL without a trailing slash (such as /docs/Web/pwa-offline), the Docusaurus service worker looks up two candidates:
https://webdevkb.dev/docs/Web/pwa-offline
https://webdevkb.dev/docs/Web/pwa-offline/index.html
This is why URLs that static hosting resolves to /index.html can also be served from cache while offline.
8. Build and deployment
npm run build:parallelbuilds each locale and merges the results intobuild/- Each locale's
sw.jsis part of the build output and is served as-is by Cloudflare Pages - Cloudflare Pages limits a single file to 25MiB.
search-index.jsonis currently 18.6MB, so it will approach that limit as more articles are added
9. Applying updates automatically
When offline mode is active, the Docusaurus PWA plugin shows a "New version available" popup while a new service worker is waiting, and holds the update until the user taps Refresh. Because this is a content site, we swizzled @theme/PwaReloadPopup into src/theme/PwaReloadPopup/index.tsx and replaced it so that a waiting service worker is applied automatically.
- When the update download completes, the page reloads itself once (no user action required)
- Update checks run at launch and on page navigations; resuming the app from the background may not trigger one
- While an update is pending, fully closing and reopening the app also activates the new service worker
Using it on Android
- Connect to Wi-Fi and open the site in Chrome
- Chrome menu → "Install app" (or "Add to Home screen")
- Launch the installed icon and stay online for a few minutes until precaching completes
- Turn on airplane mode and launch the icon; all articles and search are available
Precaching happens the first time the installed app is launched. Launching it offline first leaves the cache empty and no page can be displayed.
After a new build is deployed, the update check at launch finds the new service worker, and the app reloads itself once when the download completes (see "9. Applying updates automatically" above).
To check download completion, look at "Settings → Site settings → Storage" in Chrome (about 60MB for the site), or inspect Cache Storage in desktop DevTools (see below).
Verifying locally
npm run build
npm run serve
- Open
http://localhost:3000/?offlineMode=true - Confirm the service worker is
activatedunder DevTools → Application → Service Workers - Confirm a
workbox-precache-v2-...cache exists under Application → Cache Storage - Switch the Network tab to Offline, reload, and check that articles are still shown
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| No service worker registered | Not generated by the dev server / not HTTPS / missing ?offlineMode=true |
| Articles work but search does not | search-index.json was excluded from precache (check the size limit) |
| Stale content | The update has not been detected/downloaded yet, or the app was only resumed. Fully close and reopen the app, or clear site data |
| 404 while offline | The URL is not in the precache (e.g. a locale never opened online) |
To clear the cache, use Chrome's "Settings → Site settings → Storage" or DevTools → Application → Storage → Clear site data.
Operational notes
- Applying updates: after a new build is deployed, the update check at launch finds the new service worker, and the page reloads itself once when the download completes (no popup is shown). Update checks run at launch and on navigations; merely resuming the app from the background may not apply updates.
- Storage: about 60MB per locale in Cache Storage. Installing both ja and en roughly doubles that.
- External resources: external links, embeds such as YouTube, and images or fonts hosted elsewhere are not available offline. Mermaid diagrams are rendered by bundled JavaScript, so they display as long as the bundles are precached.
- Search index growth:
search-index.jsongrows with the number of articles. Keep both the Cloudflare Pages 25MiB limit and the Workbox size limit in mind.