0

The "--outputHashing=all" option changes the name of my files to bust the cache. This is not a great option for me. Can I get this feature to append a query string parameter (like "?v=hash"), instead of renaming the file? If output hashing won't do this, are there other easy ways to achieve this?

1
  • Could you explain a bit more why the output hashing based on the file name is not a great option for you? For me it works perfectly fine. Commented Nov 23, 2024 at 11:09

1 Answer 1

0

That would require support beyond Angular. The query string is handled by the web server, so you would need to modify the web server so that it handles the query string.

I doubt there's built-in support for anything like that in the web servers. You'd need to write some kind of script that maps the query string to wherever the actual files are. Which means you'd probably need to adjust your deployment procedure to deploy each version in, for example, a different directory, and then the query parameter is used to identify the actual directory from which to serve the files, for example.

And even so, you might need to manually edit the files (such as index.html) to reference the file with a query hash.

This seems like an XY problem (https://en.wikipedia.org/wiki/XY_problem). Perhaps you can describe the problem you're facing with filename-based hashing and someone might be able to offer some solutions for that.

Sign up to request clarification or add additional context in comments.

2 Comments

There is a commonly used cache busting strategy to change the query string parameter, instead of changing the file name. polyfills.js?v=hash1 and polyfills.js?v=hash2 both download polyfills.js from the server, but if the browser has cached hash1, the browser will ignore the cache if it is asked to request hash2. This way the file on my sever is always polyfills.js and I don't have to make accommodations for a constantly changing file name.
Chaning the file name also works by cache busting. What accommodations do you need for a changing file name? The files output by ng build are all referencing the correctly named file, you just need to serve all the files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.