-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guides - Explain Hash Changes in Caching Guide #652
Comments
If I replace So I removed the inlining of the All bundles grew a bit, but in the long-run I think that definitely is worth it. Anything else I need to be aware of, or is the change that should be recommended in https://webpack.js.org/guides/caching/#deterministic-hashes? That is from |
Btw, the reason why I extracted the manifest is because of this issue, when manifest has not been inlined: |
@jouni-kantola There's one more option - I think webpack should come with stronger defaults and treat numbered module ids as a special case that's enabled through a plugin rather than vice versa. I would default with |
I'm working with updating the docs at the moment. I realised I got things a bit backwards after-all yesterday. Yes, use So this is the simplest config I'm suggesting: var path = require('path');
var webpack = require('webpack');
var ChunkManifestPlugin = require('chunk-manifest-webpack-plugin');
var WebpackChunkHash = require('webpack-chunk-hash');
module.exports = {
entry: {
vendor: './src/vendor.js',
main: './src/index.js'
},
output: {
path: path.join(__dirname, 'build'),
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ["vendor", "manifest"],
minChunks: Infinity,
}),
new webpack.HashedModuleIdsPlugin(),
new WebpackChunkHash(),
new ChunkManifestPlugin({
filename: "chunk-manifest.json",
manifestVariable: "webpackManifest"
})
]
}; |
Directly related issue: webpack/webpack#1479 |
All right. I went through a whole bunch of scenarios to check what updated hash. I use:
This is what I came up with: I'll try to document it in docs, in some kind of overview. I'm probably leaving out the files and only describe list the actions. |
I also tried adding recordsPath,
|
@sokra: Wouldn't at least the long-term caching for code splitted chunks be fixed if they weren't prefixed with the ordering number? |
Related: #131. |
@jouni-kantola are you still interested in pr-ing some updates or a new article? It seems this is somewhat covered in the caching guide but could probably be improved. |
@jouni-kantola I found your Gist very helpful, thanks fore that. Can I ask why you added WebpackChunkHash to your set? Is HashedModuleIdsPlugin documented anywhere? Is it considered best practice to use |
I think between @timse's post and the caching guide we can probably push this past the finish line. We should definitely link to @timse's post, and maybe this tool for testing, from that guide and make any other changes necessary to bring it up to date. Once that happens, I think this issue can be closed. |
Hello! Sorry for not getting back to you guys in quite some time. The reason why I created this issue and went through the steps in the gist is to make developers aware that many things will affect long-term caching. If @timse's post is the baseline for creating long-term cacheable assets, I think that should be the caching docs from now on. Added to that I think many steps could be elaborated a bit more, just to show the effect of i.e. an extra module dependency. Basically I just repeated what @skipjack had already renamed the issue to 😉 |
Regarding official webpack blogs posts that basically are written to be docs, I think they should be created in the docs repo directly. Redundant information is one of the reasons webpack/webpack#1315 is what it is. Many sources of truth just adds to confusion (/cc @TheLarkInn & @sokra). |
@jouni-kantola no worries, and I'm glad we agree on how it should be updated. I've been cleaning up issues and trying to turn the remaining ones into actionable items that we can continue knocking off the list.
I agree although I do think the blog serves a slightly different purpose for more loose discussion and walkthroughs. However, we need to be better about first, finishing the backlog, and second, keeping things up to date and staying on top it so we don't find ourselves in the same situation of a huge backlog of things that need to be documented or resolved. The problem is, webpack is a big tool with a lot of things that need doing and, as with all open source work, people only have so much time to spare. I'm hopeful that we'll get there but it is definitely taking some time. Re this issue though, yeah I think we basically need to just review the caching guide, see what's missing, and add that. Then this issue, and probably a whole list of other ones on the main repo, can be closed out. |
Going to try to tackle this now... |
@jouni-kantola so I think I've pretty much covered everything in #1436. I didn't mention |
@skipjack: When I was testing the hashes were more consistent with the extra hashing plugins. However after a while I've seen this resulting in runtime errors. Better to leave the hashing only to webpack's substitutions. |
@jouni-kantola yeah I agree -- I think the simpler we can keep that guide the better. That's why I started from scratch with TheDutchCoder/webpack-guides-code-examples#17 and tried to only use the plugins that seemed necessary while testing. I think if any issues arise with the current guide we should first try to reproduce them in the examples repo, and then decide if it's a common enough issue to mention in the guide. |
…ifest. Current use case & Webpack 3.8.1 didn't appear to need any of various plugins and techniques described: - https://webpack.js.org/plugins/hashed-module-ids-plugin - https://webpack.js.org/plugins/named-modules-plugin - NamedChunksPlugin (built-in, mentioned in predictable caching article) - https://webpack.js.org/guides/caching/#conclusion - https://medium.com/webpack/predictable-long-term-caching-with-webpack-d3eee1d3fa31 - webpack/webpack#1315 - webpack/webpack.js.org#652 - webpack/webpack#4913 - https://gist.github.com/jouni-kantola/1c1e2bfaebf30de50d1b6a71b869da13 - https://gist.github.com/sokra/ff1b0290282bfa2c037bdb6dcca1a7aa
I got a scenario here, that I would like to discuss and hopefully create a source for docs, for what a developer should really think about to prevent causing hash changes.
I'm making something, that might seem like a very small change in my code, which has quite large effect on long-term caching.
I'm writing this issue in docs, because I'm sure it's expected, just that I want to be able to understand why this is happening, and hopefully help others as well.
Example repo is here (using
webpack@2.2.0-rc.7
andwebpack-chunk-hash@0.3.0
):https://github.com/jouni-kantola/webpack-output-by-build-type/tree/why-hash-change
Here goes the scenario:
module-a.js
from:to:
So to what I think needs to be documented:
59
to85
, and that caused three bundles to be cache busted. In a larger app that could be quite a lot of code that needs to be shipped again to the end-user. Is there anyway to prevent this small change, from having this large effect?I think I've done the most important bit, to extract the manifest, but still it's very easy to get chunks cache busted. There are loads of blogs discussing this, but I still believe the truly nitty gritty is missing to be documented.
The text was updated successfully, but these errors were encountered: