Does Angular's service worker verify cached API data it serves offline?
0 reputation · 12 Apr 2020, 09:43 UTC
Offline restore path for dataGroup responses
In an Angular PWA, the service worker generated from ngsw-config.json hash-verifies static assets against the generated manifest, so a corrupted asset served while offline is detected and treated as missing. A dataGroups entry can similarly cache API GET responses, letting the app keep rendering data after the network is gone — effectively the recovery source for that data.
The open point: the documented hash check covers assets, not dataGroup responses. Recovered API entries appear to be served as-is until maxAge or maxSize expires, and how a 304 Not Modified interacts with an existing cached entry seems to depend on the configured strategy (performance vs freshness). The documentation does not appear to settle this, so treat the detail as needing verification against the current version.
Assuming Angular 17–20 with @angular/service-worker:
- Does the service worker perform any integrity check on dataGroup responses it serves offline, or is that entirely the application's responsibility?
- Under
strategy: "freshness", is a 304 treated as a valid revalidation that keeps the cached entry, or can stale data persist? - Is an ETag or checksum comparison in application code the accepted pattern for confirming recovered data?