Skip to content

Serve per-domain ngsw.json to support Angular Service Worker with multi-domain configurations #15

Description

@PSanetra

When multiple domains are configured with different base_href or spa_config values, the server generates a per-domain index.html with the appropriate base element and spa_config hash. ngsw.json, the Angular Service Worker manifest, is however served as-is from the build output, identical for all domains.

This causes several problems:

1. Hash mismatch for index.html

ngsw.json contains pre-computed hashes of all assets, including index.html. Since the server modifies index.html at startup (injecting base_href, rewriting spa_config.js references), the served content no longer matches the hash in the manifest. NGSW will detect a perpetual update or fail integrity validation.

2. spa_config.js referenced under its original name

The manifest references spa_config.js by its build-time filename, but the server returns 404 for /spa_config.js and only serves it at /spa_config.{hash}.js. NGSW will fail to prefetch this asset.

3. Same manifest for different domains

When two domains serve different index.html content, they each need an ngsw.json with matching hashes. Currently there is no mechanism for this.

Possible solution

Process ngsw.json at startup similarly to index.html: for each configured server, rewrite the asset hashes and URLs to reflect the per-domain modifications, and route /ngsw.json requests to the correct version based on server_name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions