Add content hashes to asset URLs#6749
Conversation
Greptile SummaryThis PR adds content-hash cache busting to asset URLs. The main changes are:
Confidence Score: 4/5The remaining cache race should be fixed before merging.
reflex/assets.py Important Files Changed
Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/asset-conte..." | Re-trigger Greptile |
Merging this PR will not alter performance
Comparing Footnotes
|
| """ | ||
| versioned_path = f"{relative_path}?v={_short_content_hash(source_file)}" |
There was a problem hiding this comment.
Hash Can Precede Copy — The stability check only covers the time spent reading
source_file. The assets directory is copied into the frontend build later. If a generated asset changes after this hash is calculated but before that copy, the page keeps the old ?v= value while the public directory receives new bytes. Browsers may then reuse a cached response instead of fetching the deployed file. Hashing and copying need to use the same immutable snapshot.
Closes #6550.
Adds content-hash cache busting to
rx.assetURLs by appending an 8-character SHA-256 query parameter based on theasset file contents.
Example:
rx.asset("logo.svg")now returns/logo.svg?v=<hash>.The hash changes only when the file content changes, allowing browsers to cache assets safely across deploys.
Implementation notes:
AssetPathStr.importable_pathunversioned so existing build-time import behavior is preserved.