Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Add Offline Support to Your Web App Without Hand-Writing a Service Worker

Use Vite PWA or Angular’s CLI to generate and register a service worker, then configure what your app caches and verify it with the network disabled.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can add service-worker-based offline support without writing the worker yourself: use vite-plugin-pwa with a Vite app, or Angular’s ng add @angular/pwa setup with an Angular CLI app. The tooling can generate and register a worker, but you still need to decide which resources and routes should work offline—and design separately for app data and offline actions.

Choose the setup for your framework

Project Documented setup What it gives you
Vite vite-plugin-pwa, starting with its generated-worker approach Can generate the manifest and service worker and register the worker; caching behavior is configured for your app.
Angular CLI ng add @angular/pwa Adds Angular’s service-worker support, build integration, registration, PWA metadata and icons, plus ngsw-config.json for caching behavior.

These are stack-specific paths, not interchangeable commands for every web framework. For Vite, see the Vite PWA getting-started guide; for Angular CLI, see Angular’s service-worker setup guide.

As an Amazon Associate I earn from qualifying purchases.

What “offline support” actually covers

A service worker can make resources available from a cache when the network is unavailable. That does not automatically make every page, API response, or user workflow function offline. Decide which static resources to cache, what should happen on navigation to a page that is not cached, and how important external assets behave without a connection.

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

Static app-shell caching and application data are separate concerns. The cited setup guides demonstrate caching application resources; they do not establish that authenticated API workflows, user data, or offline writes are automatically available. If users must view or change data offline, define that behavior explicitly—including how changes are stored and what happens when the app reconnects.

Set up offline support in a Vite app

Install and configure the plugin

For a Vite project, install vite-plugin-pwa as a development dependency, then add VitePWA() to the Vite configuration as shown in the official guide. Its minimal setup generates and injects a web app manifest, generates a service worker, and registers it. The plugin uses the workbox-build Node library.

Start with the generated-worker strategy, generateSW, if its built-in behavior and configuration meet your caching needs. Configure which resources are precached or runtime-cached rather than assuming every asset or route is covered by default. Check the project’s README for the compatibility requirements of the release you select; requirements vary by version.

Configure routes and external assets

Review the Workbox generateSW documentation for options such as runtime caching, third-party fonts, and navigation-fallback exclusions. If you exclude a route through navigateFallbackDenylist, provide another offline behavior for that route; it will not receive the navigation fallback. Likewise, assets served from a CDN need appropriate caching configuration if they must load offline.

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

Use custom worker code only when needed

Vite PWA’s injectManifest mode lets you supply custom service-worker logic and injects the precache manifest during the build. It offers more control, but means authoring and maintaining worker code—the opposite of the simplest no-hand-written-worker path. The Workbox injectManifest documentation recommends checking whether generateSW is sufficient first.

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

Set up offline support in an Angular CLI app

Add Angular’s service worker

  1. From the Angular CLI project, run ng add @angular/pwa.

  2. Review the generated ngsw-config.json and adjust its resource groups and paths to match the app’s build output and offline requirements.

  3. Build the app using the production configuration, then serve that output for testing.

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

The CLI adds the Angular service-worker package and build support, imports and registers the worker, updates index.html with manifest and theme-color metadata, and installs PWA icons. Angular’s setup guide lists default cached resources such as index.html, the favicon, JavaScript and CSS build artifacts, assets, and certain images and fonts. The default image and font extension list is limited; adjust it if your app’s output paths or file types differ.

Understand Angular’s versioned cache

Angular generates a hashed ngsw.json manifest from ngsw-config.json. Its service worker treats the cached application as a coherent version rather than mixing files from different versions. When an update is available, it downloads changed resources; an already-running version may continue to be served until a later load or refresh switches to the new version. See the Angular service-worker overview for the versioning model.

Deploy securely and keep a no-worker fallback

For production, serve the app over HTTPS. Angular’s service-worker overview states: “For service workers to be registered, the application must be accessed over HTTPS, not HTTP.” Localhost is an exception for development. The same overview notes that a browser without service-worker support will not register the worker or provide its offline cache management, so the app should remain usable without it. Test the browsers your users rely on rather than assuming offline support everywhere.

Verify the offline experience

  1. Serve a production-like build from an environment that supports service workers. Angular’s setup guide demonstrates serving a production build over HTTP on localhost, which qualifies as a secure context.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  2. Open the app while online and allow the worker to install and cache its configured resources.

    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
  3. In browser developer tools, disable the network. Angular’s guide demonstrates the Network tab’s Offline throttling setting.

  4. Reload and inspect network requests. Confirm that the resources you expect are being served from the service-worker cache.

  5. Test important routes, CDN assets, and any offline data or form workflow individually; a cached app shell does not prove those cases work.

    What’s actually slowing this PC down?

    Pick the symptom - the matching free tool is one click away.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  6. Redeploy a changed build and check that update behavior is acceptable and does not leave users with incompatible resources. For Angular, verify its documented version switch; for Vite, check the behavior configured for the project.

  7. During debugging, try a private browser window to reduce confusion from a previously installed worker or stale cache.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common setup mistakes to avoid

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.