When building for production, we should utilize common chunks and split out the vendor files from the application for caching purposes. Additionally, since webpack inserts its own runtime code in every build, we should chunk that out as well, which we can inline to save an HTTP request.
WHAT?
Used the CommonChunks plugin to first split out all vendor files used from node_modules into a vendors.js file.
Additionally split out the webpack runtime code (which changes and updates on every build) into its own manifest.js file since this would also cause the vendor.js file to change and prevent it from caching.
Added a plugin to inline the manifest.js file to save an HTTP request.
Added the chunkhash which will update when the code changes and cache-bust when necessary.
Note: Since the chunkhash will only change when the chunk changes, the chunkhash for the vendor will only change if you pull in or decide not to use modules. Whereas the chunkhash for the bundle will update when the application code is changed.
WHY?
When building for production, we should utilize common chunks and split out the vendor files from the application for caching purposes. Additionally, since
webpack
inserts its own runtime code in every build, we should chunk that out as well, which we can inline to save an HTTP request.WHAT?
node_modules
into avendors.js
file.webpack
runtime code (which changes and updates on every build) into its ownmanifest.js
file since this would also cause thevendor.js
file to change and prevent it from caching.manifest.js
file to save an HTTP request.chunkhash
which will update when the code changes and cache-bust when necessary.Note: Since the
chunkhash
will only change when the chunk changes, thechunkhash
for thevendor
will only change if you pull in or decide not to use modules. Whereas thechunkhash
for thebundle
will update when the application code is changed.