contenthash vs chunkhash: handling stale cache when modules move between chunks
0 reputation · 07 Sept 2020, 17:37 UTC
The goal is to maintain effective long‑term caching of assets when a module is moved from an entry‑point specific chunk to a shared chunk created by the splitChunks plugin.
With output.filename using [contenthash] the hash reflects only the file’s own content, while [chunkhash] ties the hash to the entire chunk’s contents. When a module shifts chunks, the old chunk’s filename may stay unchanged under contenthash, potentially leaving an orphaned file that browsers could still request if the HTML still references it. The webpack documentation does not specify whether the build process automatically deletes or overwrites such stale chunk assets, or whether developers must manually clean the output directory to avoid serving outdated code.
- Does webpack automatically remove or overwrite the old chunk’s assets when a module moves to another chunk, or must the dist folder be cleared manually?
- If stale assets remain, what configuration or plugin can be used to trigger their deletion during a build?
- How does the choice between [contenthash] and [chunkhash] affect the likelihood of serving orphaned files when modules are relocated between chunks?