Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Service Workers and PWAs in Angular: How They Work, How to Set Them Up, and Where They Stop

Angular's service worker caches your app for offline and slow-network use. Learn the setup command, caching strategies, update behavior, and limits.

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.

An Angular service worker is a script that runs in the browser, intercepts your app’s requests, and answers them from a cache when it can. That cuts network dependence and lets an app load on slow or absent connections. It is one step toward a Progressive Web App (PWA), not the whole thing. Angular itself describes it as a “basic caching utility for simple offline support with a limited featureset” and points to native browser APIs for more advanced caching and offline needs.

Enable it with the CLI schematic

In an Angular CLI project, run:

ng add @angular/pwa

According to Angular’s getting started guide, the schematic:

As an Amazon Associate I earn from qualifying purchases.

  • adds the @angular/service-worker package;
  • enables service worker build support in the CLI;
  • registers the worker in the app;
  • links the web app manifest and adds theme-color metadata and icons;
  • creates the ngsw-config.json configuration file.

Open the generated ngsw-config.json afterwards. Its default file and extension patterns may not match your project’s real output paths and assets, so adjust them.

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

Requirements and fallback behavior

  • HTTPS: service workers need a secure context. Localhost is the development exception.
  • Browser support: in unsupported browsers, Angular’s worker caching and push features are unavailable. The app must keep working without the worker, and you should check whether the worker is enabled before calling its APIs.
  • Registration timing: by default the worker waits until the app stabilizes, for up to 30 seconds, so it doesn’t compete with initial rendering (Angular docs).

Source: Angular service worker overview.

Configure caching in ngsw-config.json

Angular’s configuration file separates two jobs.

Asset groups: your build output

Asset groups list the files produced by your build, such as scripts, styles and images. They are the app’s shell, cached and versioned together.

Data groups: runtime data

Data groups use URL patterns to cache runtime requests such as API responses. Only non-mutating GET and HEAD requests are cached. Because the first matching group handles a request, put more specific patterns before broader ones.

Choosing a strategy

Strategy Behavior Angular’s suggested fit
performance Favors the cache for speed; may return stale data up to the configured maxAge Rarely changing resources such as avatars
freshness Prefers the network; falls back to cache when the configured timeout expires Fast-changing values such as account balances

These examples come from Angular’s documentation; they are illustrations, not universal rules. Decide per endpoint how stale is acceptable, and how long you will wait for the network before using the cache.

How updates work

The worker reads a generated ngsw.json manifest that lists resources and their hashes. A deployed version is downloaded and cached as a unit, so an already-open tab doesn’t end up mixing files from two versions (Angular devops guide).

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

If a file’s hash doesn’t match the manifest, Angular can stop serving the suspect cached version and fall back to a network “safe mode.” Typical causes are:

  • a CDN or other intermediary serving stale files;
  • non-atomic publishing, where the manifest and files reach production at different times;
  • inconsistent build artifacts.

Publish each release as a complete, consistent set, and check how your cache layers treat the manifest and the files it references.

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

Controlling updates and push from code

SwUpdate

The SwUpdate service reports available and installed versions, can check for updates on demand, and can activate the latest version for the current tab. A common pattern is to tell users a new version is ready and let them reload.

SwPush

SwPush handles push interactions. It needs browser support and a valid payload sent from your server. Chrome DevTools can send a test payload locally, which is useful before your backend is ready. Details are in Angular’s push notifications and communications guides.

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

Limits to plan around

  • The worker is a simple caching layer, not a general offline framework. Needs like background sync or custom caching logic call for native browser APIs.
  • Mutating requests (POST, PUT and so on) are not cached by data groups, so offline writes need your own design.
  • Caching adds a deployment concern: a bad release can persist in users’ caches unless your publishing and manifest handling are consistent.

The Bottom Line

“”

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 *

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.