You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Vendor chunkhash changes when app code changes #1315
I'm trying to split my vendor code from my app code and got it all working. However, every time I change some code in my app and create a new build, the vendor file gets a new chunkhash and thus is downloaded by the clients again. The contents are exactly the same though.
Looks like a conflict between the plugin and the lastest changes. You could try a previous webpack version (thay had a bug that [chunkhash] didn't change when the content change).
But if the contents of the vendor file don't change then its hash shouldn't change right? How else are we supposed to have long term caching if the filename changes every time I make a change in my app code?
Reacted by steve zhao, Dave Landis, Roman, Terence Hong, Sergio Oliveira, Iris Schaffer, Francesco, Marwane, Jewel Mahanta, czew and 2 more
I don't really understand. Isn't the whole point of chunk-manifest-webpack-plugin to remove the child chunk hashes exactly so that the contents of the entry chunk don't change and thus its hash should stay identical? It does work like that with 1.10.1.
Yet, you're saying that 1.10.2 have actually fixed this rather then breaking it. So, is the chunk-manifest-webpack-plugin doing something wrong? Or webpack? Or in other words, how am I supposed to have a working setup where changing the app code does not change the vendor's file name? :) Like I said it seems to work with 1.10.1 but your comments confuse me..
Are you able to get such a setup working with the latest webpack, as I've tried in the example project (linked above)?
Reacted by Harsimran Bath, Ivan Babak, Dave Landis, Mark Penner and Jesse Niininen
I'm attempting the same setup as @kevinrenskers and naturally have run into the same issue. If we possibly can come up with a workaround I'd appreciate it 👍
Even going back to 1.10.1 only fixes the problem some of the time. Other times I create a build, the vendor file still gets a new file name. A fix would be extremely welcome.
@lsanwick I just add my release date after the script path in the html file (eg: lib.js?v=20150818). It's a little stupid and all of this is unnecessary if webpack's chunkHash works corretly. :(
@earslap if your cache does not invalidate when the contents of a file changes than perhaps you should look into fixing that.
Personally, I don't understand the obsession with using hashes in file names. There are far more simple, and easy to use methods of versioning files, and cache busting. This really isn't even an issue in webpack's wheel house to solve for you.
I feel like this is not something the webpack maintainers should worry about. This is not really webpack's role to fill.
Reacted by Alex Krautmann, dalimian, Mark Penner and Andrew
@michael-wolfenden prior to webpack hashes and manifest, we versioned static files using the git sha or build number, as well as setting Cache-Control: max-age=31536000
@NeoVance@michaelBenin the issue with using the git sha or version number is that if you doing continuous deployment and depoying multiple times a day, the vendor bundle version constantly changes with changes to the app bundle version thus invalidating it's cache. This is the problem that file hashes are intended to solve.
Reacted by Ian Brandt, Kostya Esmukov, Michael Wolfenden, Nick Oliver, gabn88, Adam Wamai Egesa, Arik Kfir, Alex Krautmann and Ross Kaffenberger
@earslap had the same issue, @sokra wonder if this issue is gonna be addressed with webpack4 since you are rewriting treeshaking. I hope wp4 gets long term caching right, we been burned with it 3 times now with webpack 2-3
@michaelBenin can you please explain a little bit more why custom vendor hash will not work. I mean what will happen if bundle had changed, but vendor file still referencing the old bundle. Will it cause any errors?
I was thinking of using it because all other approaches end with different hashes after CI builds, even if vendors were not changed. So want to know what caveats are here.
To a certain extent, webpack 4 improved this situation, at least reducing the frequency of vendor hash changes, but the problem still exists.
See full code here
First,npm run build, output
If you just modify src/client.js, the vendor file's hash will remain unchanged unless your modified part changes the count of split chunks.
Like, comment one async import statement in src/client.js:
I close this issue due with a very large number of questions/posts with very difference problems (include deprecated webpack versions). It's also hard to understand exactly what the problem - in the configuration or it's a real bug. Also please read https://medium.com/webpack/predictable-long-term-caching-with-webpack-d3eee1d3fa31 (some steps no needs because it is already fixed in webpack). Feel free create new issue with minimum reproducible test repo.
In short ways:
webpackConfig.output={chunkFilename: '[name]-[contenthash].chunk.js',filename: '[name]-[contenthash].js'};webpackConfig.plugins=[// ------------------------------------// Long Term Caching// ------------------------------------// More information https://medium.com/webpack/predictable-long-term-caching-with-webpack-d3eee1d3fa31newwebpack.NamedChunksPlugin(chunk=>{if(chunk.name){returnchunk.name;}// eslint-disable-next-line no-underscore-danglereturn[...chunk._modules].map(m=>path.relative(m.context,m.userRequest.substring(0,m.userRequest.lastIndexOf(".")))).join("_");}),newwebpack.HashedModuleIdsPlugin()];
Webpack@5 will have better long term caching out of box. Thanks!
Activity
alexhancock commentedon Jul 31, 2015
I am also experiencing this issue
sokra commentedon Jul 31, 2015
Looks like a conflict between the plugin and the lastest changes. You could try a previous webpack version (thay had a bug that
[chunkhash]didn't change when the content change).kevinrenskers commentedon Jul 31, 2015
Any idea which webpack version I should try?
kevinrenskers commentedon Jul 31, 2015
Seems that going back to 1.10.1 works. 1.10.2 and up break the chunkhash as described above.
sokra commentedon Jul 31, 2015
It doesn't "break" it, it fixes it. The chunk hash should change when the hashes of the child chunks change... ;)
kevinrenskers commentedon Jul 31, 2015
But if the contents of the vendor file don't change then its hash shouldn't change right? How else are we supposed to have long term caching if the filename changes every time I make a change in my app code?
sokra commentedon Jul 31, 2015
That's caused by the chunk-manifest-webpack-plugin. It move the hashes of the child chunks out of the entry chunk. I propably need to rewrite it...
kevinrenskers commentedon Jul 31, 2015
I don't really understand. Isn't the whole point of chunk-manifest-webpack-plugin to remove the child chunk hashes exactly so that the contents of the entry chunk don't change and thus its hash should stay identical? It does work like that with 1.10.1.
Yet, you're saying that 1.10.2 have actually fixed this rather then breaking it. So, is the chunk-manifest-webpack-plugin doing something wrong? Or webpack? Or in other words, how am I supposed to have a working setup where changing the app code does not change the vendor's file name? :) Like I said it seems to work with 1.10.1 but your comments confuse me..
Are you able to get such a setup working with the latest webpack, as I've tried in the example project (linked above)?
Zagitta commentedon Aug 1, 2015
I'm attempting the same setup as @kevinrenskers and naturally have run into the same issue. If we possibly can come up with a workaround I'd appreciate it 👍
kevinrenskers commentedon Aug 9, 2015
Even going back to 1.10.1 only fixes the problem some of the time. Other times I create a build, the vendor file still gets a new file name. A fix would be extremely welcome.
lsanwick commentedon Aug 13, 2015
We're seeing this issue as well, any consistent fix would be great.
airwin commentedon Aug 14, 2015
same problem. I remove the
chunkHashand use my own hash now :(.lsanwick commentedon Aug 14, 2015
If you're willing to share, what method are you using to produce a hash?
airwin commentedon Aug 18, 2015
@lsanwick I just add my release date after the script path in the html file (eg: lib.js?v=20150818). It's a little stupid and all of this is unnecessary if webpack's chunkHash works corretly. :(
175 remaining items
chen86860 commentedon Nov 13, 2017
Just named the
vendorcan solve this problem 😆code:
michaelBenin commentedon Dec 13, 2017
Anyone else coming here needing a solution, just create your own md5 hash.
Use vendorHash in the vendor filename options:
filename: `vendor.${vendorHash}.jsmichaelBenin commentedon Dec 15, 2017
Regarding my comment above - that won't work as the bundle is referenced in the vendor file.
NeoVance commentedon Jan 1, 2018
@earslap if your cache does not invalidate when the contents of a file changes than perhaps you should look into fixing that.
Personally, I don't understand the obsession with using hashes in file names. There are far more simple, and easy to use methods of versioning files, and cache busting. This really isn't even an issue in webpack's wheel house to solve for you.
I feel like this is not something the webpack maintainers should worry about. This is not really webpack's role to fill.
michael-wolfenden commentedon Jan 2, 2018
@NeoVance curious to hear what alternatives there are to file hashing
michaelBenin commentedon Jan 2, 2018
@michael-wolfenden prior to webpack hashes and manifest, we versioned static files using the git sha or build number, as well as setting
Cache-Control: max-age=31536000michael-wolfenden commentedon Jan 2, 2018
@NeoVance @michaelBenin the issue with using the git sha or version number is that if you doing continuous deployment and depoying multiple times a day, the vendor bundle version constantly changes with changes to the app bundle version thus invalidating it's cache. This is the problem that file hashes are intended to solve.
dalimian commentedon Jan 26, 2018
@earslap had the same issue, @sokra wonder if this issue is gonna be addressed with webpack4 since you are rewriting treeshaking. I hope wp4 gets long term caching right, we been burned with it 3 times now with webpack 2-3
I am willing to help with the work
maksimsemenov commentedon Feb 9, 2018
@michaelBenin can you please explain a little bit more why custom vendor hash will not work. I mean what will happen if bundle had changed, but vendor file still referencing the old bundle. Will it cause any errors?
I was thinking of using it because all other approaches end with different hashes after CI builds, even if vendors were not changed. So want to know what caveats are here.
michaelBenin commentedon Feb 9, 2018
@maksimsemenov ~
First off we didn't get this working as intended, this issue is still open.
Basically we found that the vendor file has a reference of the app.js and that caused an error breaking JS.
malliapi commentedon Apr 29, 2018
is this still happening for webpack 4?
edvardchen commentedon May 3, 2018
To a certain extent, webpack 4 improved this situation, at least reducing the frequency of vendor hash changes, but the problem still exists.

See full code here
First,
npm run build, outputIf you just modify
src/client.js, the vendor file's hash will remain unchanged unless your modified part changes the count of split chunks.Like, comment one async import statement in
src/client.js:Then

npm run buildwould outputWhy? Because the
vendors~appfile still has achunkId.Maybe we need a special way to treat initial chunk. Treat that they are already installed without checking ?
alexander-akait commentedon May 3, 2018
I close this issue due with a very large number of questions/posts with very difference problems (include deprecated webpack versions). It's also hard to understand exactly what the problem - in the configuration or it's a real bug. Also please read https://medium.com/webpack/predictable-long-term-caching-with-webpack-d3eee1d3fa31 (some steps no needs because it is already fixed in
webpack). Feel free create new issue with minimum reproducible test repo.In short ways:
Webpack@5will have better long term caching out of box. Thanks!