-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
Which @angular/* package(s) are relevant/related to the feature request?
No response
Description
Is this a feature request?
Yes
Description
In SSR Angular applications, a common production issue happens after deploying a new version:
Users who still have a previous version loaded in the browser may encounter a ChunkLoadError when navigating, due to stale HTML referencing outdated hashed bundles.
This typically happens because the server returns HTML that is cached or reused, while the underlying JS chunks have changed.
This is not a bug in Angular itself, but rather a missing default or guidance regarding cache strategy for SSR HTML responses.
Current behavior
- Angular SSR does not define any default cache headers for HTML responses
- Developers must manually configure cache headers
- If misconfigured, this can lead to:
- ChunkLoadError
- blank screens
- broken navigation after deployment
Expected behavior
"Angular SSR could provide a safer default or guidance for HTML caching strategy.
For example:
- Set
Cache-Control: no-cache, no-store, must-revalidateby default for SSR HTML responses
OR
- Clearly document recommended cache strategies for SSR applications
Why this matters
- This issue is very common in real-world production environments
- It affects application stability after deployments
- It is difficult to diagnose, especially for less experienced developers
- The fix is simple but not obvious
Additional context
This issue can be reproduced locally without CDN:
- Run an SSR Angular app
- Open it in the browser
- Deploy a new version (new build with different hashes)
- Navigate to a lazy-loaded route
- Observe ChunkLoadError
Environment
Angular: 21 (SSR)
Node: any
Browser: any
Proposed solution
Proposed solution
Provide a default cache strategy or guidance for SSR HTML responses.
Option 1 (preferred):
- Angular SSR sets
Cache-Control: no-cache, no-store, must-revalidateby default for HTML responses
Option 2:
- Add official documentation recommending cache strategies:
- HTML (SSR): no-cache
- Assets (JS/CSS with hashes): long-term cache
Option 3 (optional):
- Expose a built-in hook or configuration option to control cache headers in SSR responses
Alternatives considered
Alternatives considered
- Manually configuring cache headers at the server level (e.g., Express, Nginx)
- Adding a global error handler to reload the app on ChunkLoadError
While these approaches work, they are not obvious and require additional knowledge outside Angular.
Providing guidance or safer defaults in Angular SSR would reduce production issues and improve developer experience.