Hash on final file content

Are bundle hashes based on final compiled code?

Person in shorts with blue hair walking left


When code is transpiled and minified, it's possible to make changes to source code that have no effect on the bundled output. For example, if the minifier is removing comments, changing comments in the source code will have no effect on the output.

Conversely, there are cases where the source is unmodified, but the bundled output changes. For example, the transpiler or minifier may be updated to improve the output.

The Test

This test builds a single JavaScript module twice, with minification enabled in each tool. The comment text is changed in the second build, which should have no effect on the resulting bundle.


/* This code is copyright 2020 */

Since minification removes comments, changing the comment to 2021 does not change the bundled output and should produce the same hashed URL.



Hashing solutions for Gulp like gulp-rev-all are typically performed as the last step, after minification. As long as hashing is the last transform in the chain, hashes are calculated on final bundle/file contents.


Parcel calculates hashes based on the final contents of generated bundles. As a result, code changes that don't result in a change to a bundle's contents preserve its same hash and avoid unnecessary invalidation.


Rollup calculates hashes for bundles based on their contents prior to final output generation.



Changes to comments change the hash of the file, even though the minified output is identical. Changes in Webpack as well as terser-webpack-plugin are necessary to make this pass.