This example demonstrates the AggressiveSplittingPlugin for splitting the bundle into multiple smaller chunks to improve caching. This works best with a HTTP2 web server elsewise there is an overhead for the increased number of requests.
The AggressiveSplittingPlugin split every chunk until it reaches the specified maxSize. In this example it tries to create chunks with <50kB code (after minimizing this reduces to ~10kB). It groups modules together by folder structure. We assume modules in the same folder as similar likely to change and minimize and gzip good together.
The AggressiveSplittingPlugin records it's splitting in the webpack records and try to restore splitting from records. This ensures that after changes to the application old splittings (and chunks) are reused. They are probably already in the clients cache. Therefore it's heavily recommended to use records!
Only chunks which are bigger than the specified minSize are stored into the records. This ensures that these chunks fill up as your application grows, instead of creating too many chunks for every change.
Chunks can get invalid if a module changes. Modules from invalid chunks go back into the module pool and new chunks are created from all modules in the pool.
There is a tradeoff here:
The caching improves with smaller maxSize, as chunks change less often and can be reused more often after an update.
The compression improves with bigger maxSize, as gzip works better for bigger files. It's more likely to find duplicate strings, etc.
The backward compatibility (non HTTP2 client) improves with bigger maxSize, as the number of requests decreases.
{{webpack.config.js}}{{stdout}}
{{production:stdout}}
{{dist/records.json}}