Skip to content

@angular/build 22.1.4+: new modulepreload hints for shared chunks are discarded by Chrome ("cross-world service worker resource mismatch") when served by @angular/service-worker #34022

Description

@Sergiobop

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

22.1.3

Description

Since 22.1.4, shared chunks get <link rel="modulepreload"> hints, which Chrome discards with a "cross-world service worker resource mismatch" warning when ngsw serves them

Which @angular/ package(s) are the source of the bug?*
@angular/build (application builder) — behaviour change introduced by #33793 (22.1.4 backport 46fcb29).

#33793 fixed the chunk optimizer so that statically imported shared chunks are stored in initialFiles (previously the record was created but never set). A side effect not mentioned in the PR: index-html-generator now emits up to MODULE_PRELOAD_MAX (10) <link rel="modulepreload"> hints for those chunks. Before 22.1.4 our production index.html had 0 such hints; from 22.1.4 it has 10, with identical application code (bisected commit by commit, building with ng build --configuration production).

When the app is served by the Angular service worker (@angular/service-worker, assetGroup app in prefetch mode), every repeat visit where the SW already controls the page logs one warning per hint in Chrome:

A preload for 'https:///chunk-XXXX.js' is found, but is not used because it is a cross-world service worker resource mismatch.

The preload is fetched from the network by the document while the real module request is answered by the service worker from Cache Storage, so Chrome discards the preloaded response. Net effect on repeat visits with an active SW: the preloaded bytes are downloaded and thrown away.

Minimal Reproduction

  1. ng new with --ssr false, add @angular/service-worker (ng add @angular/service-worker), keep the default ngsw-config.json.
  2. Add enough lazy routes sharing common code so the chunk optimizer runs (>= optimizeChunksThreshold, default 3 lazy chunks) and produces shared chunks statically imported by initial code.
  3. ng build --configuration production with @angular/build@22.1.3index.html has no modulepreload; with 22.1.4 → N modulepreload links.
  4. Serve dist/, load twice so the SW controls the page, open DevTools console → warnings above.

Exception or Error

> A preload for 'https://<host>/chunk-XXXX.js' is found, but is not used because it is a cross-world service worker resource mismatch.

Your Environment

Angular CLI / @angular/build 22.1.7, @angular/service-worker 22.1.5, Chrome 151 (Windows and Android).

Anything else relevant?

Either the optimizer should not mark SW-served shared chunks as preload candidates, or the docs should point out that apps using @angular/service-worker should set "index": { "input": "src/index.html", "preloadInitial": false } to avoid redundant downloads and console noise. Alternatively, preloadInitial could default to false when the build includes a service worker (serviceWorker option set).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions