Tree‑shaking vs Manual Chunks: Which Cuts Bandwidth for Low‑Traffic Pages?
0 reputation · 22 Mar 2021, 01:56 UTC
0 reputation · 22 Mar 2021, 01:56 UTC
Minimize the amount of data transferred for a single page that receives a small number of visits per month.
Rollup removes unused ES module exports by default, but the extent of size reduction depends on side‑effect annotations and the presence of dynamic imports. Manual chunks can split the bundle into route‑specific pieces, increasing the HTTP request count unless served over HTTP/2. The trade‑off also varies across Rollup major versions; output.manualChunks defaults and behavior have shifted between v3 and v4.
Because the page is low‑traffic, the cost of additional requests may be negligible, yet the savings in initial payload could impact user experience on slow connections.
It remains unclear whether the default tree‑shaking alone provides sufficient bandwidth savings, or whether manual chunking yields a measurable benefit that outweighs the extra request overhead.
Will tree‑shaking alone suffice to reduce bandwidth on a low‑traffic page, or does manual chunking provide a measurable benefit? How does the cost of additional HTTP requests balance against the savings in bundle size under HTTP/2? What Rollup version differences could affect this trade‑off?
35275 reputation · 22 Mar 2021, 08:53 UTC
For a low-traffic page, tree-shaking alone is usually sufficient if the resulting bundle is under 200 KB. Manual chunking only provides a measurable bandwidth benefit if you are importing large, heavy libraries that are not fully tree-shakable and you are serving the site over HTTP/2.
Tree-shaking reduces the total amount of code sent by removing unused ES module exports. Manual chunking does not remove code; it redistributes it into separate files to reduce the initial payload of a specific entry point.
The behavior of output.manualChunks differs between major versions. In Rollup v3, splitting was more aggressive. Rollup v4 shifted toward splitting only when a module is shared by multiple entry points. If you are using v4, you may need to be more explicit in your manualChunks function to achieve the same isolation as in v3.
To determine which strategy is working for your specific page, follow these steps:
rollup-plugin-visualizer to identify the largest modules in the bundle.manualChunks function to isolate the largest identified library into its own file.Missing Diagnostic: Are you using dynamic import() statements for any of the page's features? If so, those modules are already chunked by default, making manual chunking redundant for those specific assets.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.