Are Rollup content hashes a safe caching contract across major upgrades?
0 reputation · 01 Sept 2024, 17:47 UTC
0 reputation · 01 Sept 2024, 17:47 UTC
We use Rollup's output.entryFileNames and chunkFileNames with [hash] placeholders so browsers and our CDN can cache emitted chunks long-term. This works well within a single Rollup version, but we are unsure what guarantees exist when we upgrade.
The documentation describes how hashes are generated from chunk content, but I cannot find a clear statement about whether the hashing algorithm, chunk-splitting heuristics, or default output formats are stable across major versions (for example 3.x to 4.x). If an identical source tree produces different chunk boundaries or different hashes after an upgrade, every cached URL changes at once, which effectively invalidates our long-term caching strategy and complicates comparing pre- and post-upgrade builds.
We pin the exact Rollup version and commit our lockfile, so rollback itself is not the concern; the concern is knowing which parts of the emitted output we can treat as a contract.
Is chunk content hashing documented as stable across major versions, or explicitly not guaranteed? Are chunk-splitting decisions part of any stability guarantee, or only the plugin hook API? What do teams relying on long-term caching typically diff (file names, hashes, warnings) to verify an upgrade is output-equivalent before shipping it?
31775 reputation · 02 Sept 2024, 01:20 UTC
No. Rollup does not publish a formal guarantee that the hash value embedded in output.entryFileNames or output.chunkFileNames will stay identical when you upgrade between major releases. The hashing algorithm, chunk‑splitting heuristics, and even default output format are all internal implementation details that have changed between 3.x and 4.x, and they are not version‑pinned in the public API.
output.format and source‑map handling affect the hash calculation. A change in defaults can alter the hash even if the code itself is unchanged.Rollup’s documentation explains that [hash] is derived from the chunk content, but it does not state that the algorithm or the set of data used to compute it is stable across major releases. The only part that is stable is the hash placeholder itself, not the underlying value.
package.json and lock the dependency graph with npm ci or yarn install --frozen-lockfile.dist-v3 and dist-v4).diff -rq dist-v3 dist-v4
# or use a tool that compares file names and hash parts only
| Check | Tool / Command | What to look for |
|---|---|---|
| File names | grep or ls | Same set of names, same hash segment |
| Hash segment | awk/sed to extract the hash part | Exact match or explain why it differs |
| Content equality | sha256sum of files | Same content if hash differs |
| Plugin side‑effects | Check plugin docs for changes in output format | Ensure no new metadata added that changes hash |
To fine‑tune the approach, we’d need to know the target Rollup version you plan to upgrade to. Different major releases may introduce different changes that affect the hash calculation.
Assume the hash contract is not guaranteed across major Rollup upgrades. Treat it as an implementation detail and validate the output after each upgrade before relying on CDN cache keys.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.