Skip to content
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

Use [contenthash] over [hash] and [chunkhash] for better long term caching #2096

Closed
alexander-akait opened this issue May 2, 2018 · 9 comments

Comments

@alexander-akait
Copy link
Member

alexander-akait commented May 2, 2018

For long term caching better use [contenthash] over [chunkhash].

From slack

sokra [2:59 PM]
A chunk contains modules i. e. a.js, b.css, and c.wasm. This results in 3 assets being generated JS, CSS and WASM. `[chunkhash]` is the hash of the complete chunk, which is JS + CSS + WASM. `[contenthash]` is the hash of the content of the file, which is different for each asset.

evilebottnawi [3:10 PM]
I.e. better use `[contenthash]` for chunks?

sokra [5:26 PM]
@evilebottnawi better use `contenthash`.

sokra [5:30 PM]
we probably should rename that in webpack 5 to `[hash]`.

evilebottnawi [5:34 PM]
Only one question why we need `chunkhash` after implement `contenthash` :smile: ?

sokra [5:39 PM]
not sure if there is a use case where chunkhash is better, but at least for backward-compat

Ref on issue in webpack webpack/webpack#7138.
Example of problem webpack-contrib/mini-css-extract-plugin#117.

@FadySamirSadek
Copy link
Member

@evilebottnawi @montogeek does this mean chunkhash should be removed from the exampled in the guide and replaced with contenthash with only a mention that sometime it existed so people know it is still supported ?

@alexander-akait
Copy link
Member Author

@FadySamirSadek alright, just backward compatibility

@alexander-akait
Copy link
Member Author

@FadySamirSadek friendly ping, can we solve this problem faster? Looks like many people faced with this

@FadySamirSadek
Copy link
Member

@evilebottnawi will finish it by the end of today

@alexander-akait
Copy link
Member Author

/cc @FadySamirSadek

@Streemo
Copy link

Streemo commented May 20, 2018

I had this config and was running into the issue where a change in ./src/styles.css would cause the chunkhash for the main output js file to change, even if ./src/index.js was constant:

config = {
  entry: "./src/index.js",
  plugins: [
    new MiniCSSExtractPlugin({filename: "[contenthash].css"}),
    ...
  ],
  output: {filename: "[chunkhash].js"},
  ...
}

Changing the output to {filename: "[contenthash].js"} fixed the issue, causing the browser to only reload the changed css file, as expected. Does anyone have a good link to the documentation on "[contenthash]"? I was unable to find it.

@FadySamirSadek
Copy link
Member

@Streemo I am working on fixing the documentation of [contenthash] but it has not been published yet

@Streemo
Copy link

Streemo commented May 20, 2018

@FadySamirSadek Awesome. One thing that confused me were the numbers added at the front of some of the content hashes e.g. **2.**9ff51031b7fe51cc21e6.js.gz, **1.**38ffde1f4124434ec546.js.gz which I noticed are not present in the [chunkhash]. Out of curiosity, are these ids of some sort and why are they required?

@EugeneHlushko
Copy link
Member

I think this can be closed via #2098
Please ping here if there is still an issue in the docs regarding chunkhash -> contenthash

apepper added a commit to Scrivito/scrivito_example_app_js that referenced this issue Feb 6, 2020
If I'm not mistaken, this currently outputs the same hash. But https://webpack.js.org/guides/caching/ and webpack/webpack.js.org#2096 recommends "[contenthash]".
khalwat added a commit to nystudio107/annotated-webpack-config that referenced this issue Aug 13, 2020
Bcdo added a commit to Bcdo/project that referenced this issue Aug 14, 2020
- Added `--no-tablespaces` to the mysqldump command options to work around changes in MySQL

 Fixed
- Modern config only for local dev, [fixing multi-compiler issues](webpack/webpack-dev-server#2355) with HRM
- Fix redis session config to use `App::sessionConfig()`

Changed
- Remove `[hash]` from dev config to eliminate potential [memory errors](webpack/webpack-dev-server#438)
- Use `[contenthash]` in production instead of [hash or chunkhash](webpack/webpack.js.org#2096)

- Readme file to give proper credit

-
-
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants