Cache busting for icons & language files - #8710
Conversation
otherwise react-sdk can't build anymore with riot-web in a specific location
…the unit tests in ci, where riot-web is a subdirectory of react-sdk
900e603 to
c2d1439
Compare
|
unit tests on react sdk are currently broken... |
jryans
left a comment
There was a problem hiding this comment.
Overall, this looks great! 😁 I am excited to see this merge.
| // riot-web/webapp/i18n during build by copy-res.js | ||
| test: /\.*languages.json$/, | ||
| type: "javascript/auto", | ||
| use: [ |
There was a problem hiding this comment.
Since there's only one loader for this test, you should be able to remove the use: [ ] part and fold the loader and options keys into the main object (see .wasm as an example).
| fs.writeFileSync(dest + lang + '.json', JSON.stringify(translations, null, 4)); | ||
| const json = JSON.stringify(translations, null, 4); | ||
| const jsonBuffer = Buffer.from(json); | ||
| const digest = loaderUtils.getHashDigest(jsonBuffer, "sha512", "base64", 7); |
There was a problem hiding this comment.
I think base64 includes /, which could get weird for things in file paths. Also, I'm not sure how much it actually impacts build time, but sha512 seems like overkill for this problem... We really only need the simplest thing that gives a different value when the file changes. (Also we're only keeping 7 bytes of it, so powerful hashes like sha512 are mostly doing work that is thrown out.)
For images via Webpack we're currently using [hash:7], which seems to equate to getHashDigest(buffer, null, null, 7), which will then default to md5 and hex, which seems fast, safe, and sufficient for the problem here.
jryans
left a comment
There was a problem hiding this comment.
Great, this looks ready to go! Thanks for working on this. It should be quite helpful! 😁
|
Can this/should this be applied to config.json as well? #7241 |
Hmm, I don't think we can use the same approach for config.json, as it's not part of Riot's build process. I don't think we would want to entangle it in the build process either, as people might use other configuration management systems (Ansible, etc.) to produce and manage the file. |
React-SDK PR: matrix-org/matrix-react-sdk#2658
For i18n, I changed the copy-res.js script to generate content-hashed filenames and include those in languages.json, which then gets a content-hashed filename with file-loader.
Fixes #4136