Skip to content

Conversation

@ybnd
Copy link
Member

@ybnd ybnd commented Feb 5, 2026

References

Description

DSpace Angular's production server can modify the configuration it serves to CSR-only clients through YAML or environment variables. However, these files can remain cached in the browser and leave users with out-of-date configuration until the TTL runs out or the user does a "hard refresh". On build time this sort of problem is solved by saving the content hash as part of the path of each file (JS, CSS, ...)

We introduce HashedFileMapping to bridge the same gap for dynamic content generated after the server is built:

  • Files added to this mapping on the server are copied to a hashed path
  • A copy is injected into index.html, where clients can read it out and resolve the hashed paths
  • If a given path is not found in the mapping, the client will fall back to the original version (to prevent errors in development mode)

With this mechanism we can ensure updates to config.json and similar files take immediate effect without losing the performance benefit of client-side caching.

Compression support is included in anticipation of a pending PR for #3961, where the initial size of config.json can become large enough where compressing it would be a plus.

Discussion

  • It's not clear how/if we can unit test this at the time of writing
  • Should we inlude a configuration flag to toggle this feature on/off? We may want to roll it out as opt-in so downstream users can wait it out until it has been battle-tested a bit.

Instructions for Reviewers

To test:

  1. Run DSpace Angular locally, in production mode
  2. Confirm that you see the following files:
    • [dist]/assets/config.<hash>.json → hashed configuration file
    • [dist]/dspace-theme.<hash>.css → hashed theme CSS file
    • [dist]/index.html → index file with an extra script#hashed-file-mapping element containing the mapping of plain paths to hashed paths
  3. Confirm that config.<hash>.json and dspace-theme.<hash>.css are correctly served to the browser, and that the app runs/looks as before the PR
  4. Confirm that Angular runs with stale configuration when SSR is bypassed #3992 is resolved

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You do not need to complete this checklist prior creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • My PR aligns with Accessibility guidelines if it makes changes to the user interface.
  • My PR uses i18n (internationalization) keys instead of hardcoded English text, to allow for translations.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

ybnd added 7 commits February 14, 2025 00:11
DSpace Angular's production server can modify the configuration it serves to CSR-only clients through YAML or environment variables.
However, these files can remain cached in the browser and leave users with out-of-date configuration until the TTL runs out or the user does a "hard refresh".
On build time this sort of problem is solved by saving the content hash as part of the path of each file (JS, CSS, ...)

We introduce HashedFileMapping to bridge the same gap for dynamic content generated _after_ the server is built:
- Files added to this mapping on the server are copied to a hashed path
- A copy is injected into index.html, where clients can read it out and resolve the hashed paths
- If a given path is not found in the mapping, the client will fall back to the original version (to prevent errors in development mode)

With this mechanism we can ensure updates to config.json and similar files take immediate effect without losing the performance benefit of client-side caching.
The JSON mapping needs to be declared as a data block, otherwise browers may complain (nothing seems to really break though, except for Cypress)
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#any_other_value
Mainly for 8.x and beyond, where ThemeService is injected more often ~ standalone components
Both the configuration and theme CSS are known to be needed for every render.
We can save some time by retrieving them as soon as the HTML is read.
This didn't work well in one specific case: requests without a path (e.g. https://demo.dspace.org)
Such requests would result in a 304 redirect directly to index.html, losing the hashed file mapping and causing it to get cached.
Then it could remain in the cache across rebuilds.

Solutions:
- Don't try to hash index.html, but modify it in place
- Introduce configuration to disable caching for specific static files and apply this to index.html to prevent similar problems
- Don't let browsers cache index.html when it's served for CSR under another path
….0' into cache-bust-dynamic-configuration-main
@ybnd ybnd force-pushed the cache-bust-dynamic-configuration-main branch from 920aed9 to 0c7c174 Compare February 5, 2026 09:38
@ybnd ybnd closed this Feb 5, 2026
@ybnd
Copy link
Member Author

ybnd commented Feb 5, 2026

My bad, we already had a PR ready

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angular runs with stale configuration when SSR is bypassed Add hash/fingerprint to the custom-theme CSS files

1 participant