Tree shaking
A bundler optimization that removes unused code from the final bundle by analyzing import graphs.
In long form.
Tree shaking works on ES modules: the bundler reads imports and exports statically, determines which exports are actually used, and drops the rest. Effectiveness depends on the source code being properly modular — a library that exports a single big object (`export default { fn1, fn2, fn3 }`) tree-shakes poorly; named exports (`export function fn1`, `export function fn2`) tree-shake cleanly. CommonJS modules historically don't tree-shake; ESM does. Most modern libraries publish ESM builds.
When auditing a slow site's bundle, we look for imports that pull in entire libraries (lodash, moment) when only one function is needed. The fix is usually a named import (`import { debounce } from 'lodash-es'`) or a smaller alternative (`date-fns` instead of moment).
Talk to us about your engagement.
Discovery calls are free. Scope, timelines, and pricing are quoted after we understand what you’re solving.