Skip to main content

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.

RequirementRoleImplementation on this site
HTTPSService workers only run in secure contextsServed over HTTPS by Cloudflare Pages
Web App ManifestDefines the app name, icons, start URL, and display modestatic/manifest.json
Service WorkerA proxy between the network and the page; owns caching and offline responsesGenerated by @docusaurus/plugin-pwa

Comparison with a regular website and a native app​

AspectRegular websitePWANative app
InstallationNone (just open the URL)Add to home screen from the browserInstall from a store
OfflineNot possible (relies on browser cache)Possible via service workerPossible
UpdatesReflected on reloadService worker updates on next launchThrough the store
DistributionURLURL (no store)Store review
Device capabilitiesLimitedProgressively 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.

GoalStatusNotes
Periodic data fetching while the app is closedPartialPeriodic 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 uploadsPartialBackground Sync / Background Fetch (Chromium only). Not available in Safari / Firefox; you must retry on next launch
Background location tracking / geofencingNoNo web API exists (foreground geolocation only)
Background BLE scanning / beacon detectionNoWeb Bluetooth works only in the foreground
Long-running uploads / downloadsPartialBackground Fetch (Chromium only). On Safari the page must stay open
Launch at OS loginPartialUser-configurable on Chromium desktop (apps cannot control it)
A service worker is not a server

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, Notification does 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 / capabilityWhat it enablesSupport
Web BluetoothCommunication with BLE (GATT) devicesChromium (desktop and Android) only; not Safari or Firefox
Web NFCReading and writing NFC tagsChrome for Android only; no card emulation (payments)
WebUSBLow-level USB device communicationChromium only; devices not claimed by an OS driver
Web Serial / WebHIDSerial and HID device communicationMostly Chromium desktop; not Safari or Firefox
Camera / microphoneCapture and recordingYes; no RAW capture or manual exposure control
GeolocationCurrent positionYes (foreground only); no background tracking
BiometricsBiometric sign-inYes (WebAuthn / passkeys)
VibrationVibrationChrome for Android yes; iOS has no Vibration API
ARAR via WebXRChromium 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​

CapabilityStatusNotes
Home screen / lock screen widgetsNoWidgetKit and Android widgets are native-only
Live Activities / Dynamic IslandNoActivityKit is native-only
Watch apps (Apple Watch / Wear OS)NoNot available on the web
Car (CarPlay / Android Auto)NoNot available on the web
Voice assistant integration (Siri Shortcuts, etc.)No—
Share sheet registration (share target)PartialChromium (Android and desktop) only; requires installation
File associations (open by double-click)PartialChromium desktop only
Custom URL scheme registrationPartialChromium desktop only
Tray / menu bar iconNo—
Global hotkeysNo—
Contacts, calendar, health dataNoNo web APIs (contact picking only via Contact Picker on Chrome for Android)
Phone / SMS / VoIP incoming-call UINoNo 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​

ItemStatusNotes
iOS App Store distributionNoPure PWAs are not accepted; wrappers can be rejected as "minimum functionality" (Guideline 4.2)
Google PlayPartialPossible by wrapping in a Trusted Web Activity (TWA)
Microsoft StoreYesPWAs can be submitted as-is
Store features (search discovery, reviews, staged rollout, TestFlight, etc.)No—
In-app purchases (StoreKit / Play Billing)NoWeb payments are possible, but store billing, subscription management, and refunds are not
MDM / enterprise distributionNoDesktop Chrome / Edge management policies can distribute web apps as an exception
Automatic install promptPartialAndroid 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​

RequirementSuitable technology
Content and documents (a reading site like this one)PWA
Forms, booking, e-commerce, internal toolsPWA
Notification-centric apps (if requiring installation on iOS is acceptable)PWA
Foreground camera / location usePWA
Background location, BLE, geofencingNative
Peripherals (BLE / NFC / USB) on iOSNative
Widgets, watch, car, healthNative
App Store distribution and store billingNative (or a wrapper)
High-end 3D games, video editingNative

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​

FilePurpose
package.jsonAdds @docusaurus/plugin-pwa
docusaurus.config.tsPlugin options (precache conditions, size limit, <head> tags)
static/manifest.jsonWeb App Manifest
static/img/pwa-icon-192.png / pwa-icon-512.pngIcons for installation
src/theme/PwaReloadPopup/index.tsxSwizzled 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',
},
],
},
],
],
Generated only in production builds

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.json and /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.

StrategyCondition
appInstalledThe app is installed (appinstalled event / getInstalledRelatedApps())
standaloneLaunched from the home screen icon (display-mode: standalone)
queryStringAccessed with ?offlineMode=true
mobileViewport width of 996px or less (not used here)
saveDataData Saver is enabled
alwaysAlways 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.

The service worker is always registered

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:

LocaleService workerEntriesTotal size
ja/sw.js1734~63MB
en/en/sw.js1716~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.

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:parallel builds each locale and merges the results into build/
  • Each locale's sw.js is part of the build output and is served as-is by Cloudflare Pages
  • Cloudflare Pages limits a single file to 25MiB. search-index.json is 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​

  1. Connect to Wi-Fi and open the site in Chrome
  2. Chrome menu → "Install app" (or "Add to Home screen")
  3. Launch the installed icon and stay online for a few minutes until precaching completes
  4. Turn on airplane mode and launch the icon; all articles and search are available
The first run must be online

Precaching happens the first time the installed app is launched. Launching it offline first leaves the cache empty and no page can be displayed.

Updates are applied automatically

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
  1. Open http://localhost:3000/?offlineMode=true
  2. Confirm the service worker is activated under DevTools → Application → Service Workers
  3. Confirm a workbox-precache-v2-... cache exists under Application → Cache Storage
  4. Switch the Network tab to Offline, reload, and check that articles are still shown

Troubleshooting​

SymptomCause and fix
No service worker registeredNot generated by the dev server / not HTTPS / missing ?offlineMode=true
Articles work but search does notsearch-index.json was excluded from precache (check the size limit)
Stale contentThe 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 offlineThe 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.json grows with the number of articles. Keep both the Cloudflare Pages 25MiB limit and the Workbox size limit in mind.

References​