Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can add offline support without writing a service worker from scratch: use vite-plugin-pwa for a Vite app or Angular’s ng add @angular/pwa for an Angular CLI app. The tooling can generate and register the worker, but you still need to decide which files, routes, and app data should work offline—and test those behaviors in a production build.

Choose the setup for your framework

Project Documented setup Worker approach
Vite vite-plugin-pwa, configured in Vite Start with generated generateSW behavior
Angular CLI ng add @angular/pwa Angular’s service worker, configured through ngsw-config.json

These are framework-specific routes, not interchangeable commands for every web app. The Vite PWA guide documents its plugin, while Angular’s setup guide documents the Angular CLI flow.

Set up offline support in a Vite app

Install and configure the plugin

In a Vite project, install vite-plugin-pwa as a development dependency and add VitePWA() to the Vite configuration. The plugin’s minimal setup generates the web app manifest and service worker, and adds registration code. Follow the official Getting Started guide for the current installation command and configuration syntax.

The guide’s simple example includes VitePWA({ registerType: 'autoUpdate' }). That setting is an example, not a guarantee that every app should adopt the same update behavior; choose and verify the update experience for your app.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start with a generated worker

For ordinary precaching and runtime caching, begin with the generated-worker strategy, generateSW. Configure what should be cached and how navigations and network requests should behave. A generated worker removes the need to author worker logic for common cases, but it does not determine every app-specific offline requirement for you. See the Workbox generateSW documentation for configuration examples and limitations.

  • Static assets: confirm the app’s built files are included, and explicitly account for any required third-party or CDN resources.
  • Navigation: decide what users should see when a route is opened offline. The Workbox guide documents navigation-fallback exclusions; excluded routes need their own offline handling.
  • API and app data: static asset caching does not automatically make authenticated data, API reads, or form submissions available offline. Design and test those behaviors separately.

When custom worker logic is necessary

If the generated strategy cannot express the required behavior, Workbox’s injectManifest path lets you provide custom service-worker logic and injects a precache manifest during the build. It gives more control, but requires writing and maintaining worker code, so it is not the no-hand-authored-worker route. Workbox recommends checking whether generateSW is sufficient first; see the injectManifest documentation.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Plugin compatibility depends on the release you select. Check the vite-plugin-pwa README for that release’s requirements rather than treating a version-specific Node or Vite requirement as permanent.

Set up offline support in Angular

Run the Angular CLI setup

From an Angular CLI project, run:

ng add @angular/pwa

Angular’s CLI adds the service-worker package and build support, imports and registers the worker, updates index.html with manifest and theme-color metadata, installs PWA icons, and creates ngsw-config.json for cache configuration. Build the app after setup, following Angular’s Getting Started guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Review what Angular caches

Angular’s generated configuration covers application resources such as index.html, the favicon, JavaScript and CSS build artifacts, assets, and selected image and font types. The documented default image and font extension list is limited, and paths may need adjustment if your build output changes. Inspect ngsw-config.json against the actual resources your app needs offline.

Angular’s service worker uses a hashed ngsw.json manifest generated from that configuration. Its versioned caching model treats the app as a coherent version rather than mixing files from different versions. When an update is available, the worker downloads changed resources; users can continue receiving the installed version until a later load or refresh switches to the new one. See the Angular service-worker overview and setup guide.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Plan for offline data, routes, and updates

Separate the app shell from app data

A cached shell can load without a network connection, but that alone does not make dynamic or user-specific experiences offline-capable. For each important workflow, determine what data must be available locally, what a user may change offline, and what should happen when the app reconnects. Test these workflows independently of static files; the setup guides do not establish that authenticated API operations or offline writes work automatically.

Make update behavior intentional

Updates are part of the user experience, not just a build setting. Angular documents a versioned cache that keeps a running version coherent and switches to an updated version on a subsequent load or refresh. With Vite PWA, behavior depends on the selected configuration. Test a deployment update and confirm that users are not left with incompatible app files or workflows.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Deploy securely and verify the offline experience

Service-worker registration in production requires HTTPS. Angular’s official overview states: “For service workers to be registered, the application must be accessed over HTTPS, not HTTP.” Localhost is an exception for development. Browsers without service-worker support will not provide service-worker cache management, so the app should still have a sensible non-offline fallback. See the Angular overview.

  1. Build and serve the production output. Use a server that supports service workers; Angular’s setup guide demonstrates a production build and local HTTP server. Localhost qualifies as a secure context for development.
  2. Load the app while online. Give the worker a chance to install and cache the resources specified by your configuration.
  3. Disable the network and reload. In browser developer tools, use the Network tab’s Offline throttling setting, as shown in the Angular setup guide.
  4. Inspect requests and routes. Confirm expected assets load from the service-worker cache. Check key routes, external assets, and any offline data workflows individually.
  5. Test a redeployment. Change and redeploy the app, then check how the new version becomes available and whether the old version remains usable during the transition.
  6. Debug with a clean browser state. Use a private window when testing to reduce confusion from an older worker or cached files.

Passing an offline reload test proves only that the resources and paths you tested work under that condition. It does not establish that every route, external dependency, or data operation works offline.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.