Skip to content

Conversation

@AbhinavS96
Copy link
Contributor

References

DSpace 10 port of #3993

Description

See original PR

Instructions for Reviewers

To test:

Run DSpace Angular locally, in production mode

  1. Confirm that you see the following files:

  2. [dist]/assets/config..json → hashed configuration file

    • [dist]/dspace-theme..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
    • Confirm that config..json and dspace-theme..css are correctly served to the browser, and that the app runs/looks as before the PR
  3. Confirm that Angular runs with stale configuration when SSR is bypassed #3992 is resolved

Checklist

  • 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 8 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
- Track head links in a Map, because Set doesn't deduplicate them properly
- Make ServerHashedFileMapping independent of ThemeConfig
- Make theme pre-fetching configurable (e.g. only prefetch the main theme CSS, but leave route-based theme CSS lazy)
@AbhinavS96 AbhinavS96 force-pushed the cache-bust-dynamic-configuration_contribute-main branch 5 times, most recently from caec2b4 to f994389 Compare December 18, 2025 08:47
…bust-dynamic-configuration_contribute-main
@AbhinavS96 AbhinavS96 force-pushed the cache-bust-dynamic-configuration_contribute-main branch from f994389 to ebb4c0e Compare December 18, 2025 09:45
@alexandrevryghem alexandrevryghem added bug performance / caching Related to performance, caching or embedded objects configuration labels Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug configuration performance / caching Related to performance, caching or embedded objects

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants