tooling.report

feature

Basic JavaScript hashing

Are bundle URLs hashed based on their contents?

Person in shorts with blue hair walking left

Introduction

Will the library hash bundled JavaScript? Does the hash change only when the content of the file changes?

The Test

This test bundles a single JavaScript module, with hashed URL generation enabled for each tool. The test is run multiple times, with the contents of index.js changed for the final run.

index.js

console.log('foo'); // "bar" in run 3

The result of this test should be a single JavaScript bundle with a hashed URL. Re-running the test without changing index.js should result in the same bundle and hash being generated. Re-running the test after changing the contents of index.js should output a new bundle with a different hashed URL.

Conclusion

browserify

The gulp-hash plugin lets you add hashes to filenames.

parcel
rollup
webpack

Webpack's [contenthash] hashing is based on the file contents, which means hashes only change when the resulting output can differ.