tooling.report

feature

Hash on final file content

Are bundle hashes based on final compiled code?

Person in shorts with blue hair walking left

Introduction

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.

index.js

/* This code is copyright 2020 */
console.log('Yay');

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

Conclusion

browserify

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

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

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

Issues

webpack

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.

Issues