liveBook · Manning

Tree-shaking

As explained in Secrets of the JavaScript Ninja, Third Edition

Tree-shaking is a build-time optimization that removes unused code from a program by analyzing its module dependencies and exports.

Tree-shaking removes unused code from a program by analyzing module dependencies and exports. It helps limit browser code bloat: even code that never runs still has to be downloaded and parsed, using bandwidth and CPU. section 1.4.1 section 13.0

ES modules enable better tree-shaking, one engineering reason for their growing use in JavaScript. Tree-shaking is one way to reduce unnecessary code; production flags and lazy loading are other approaches. section 1.4.1 section 13.0

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Defines tree-shaking through dependency and export analysis, but gives no implementation steps.
How it connects
Connects tree-shaking to ESM, CommonJS, and bundlers in discussions of JavaScript modules and distribution.

Also explained in

Compare how 5 books explain tree-shaking →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.