Build fluency in the vocabulary of statically determining and removing a bundle's unused exports.
0 / 5 completed
1 / 5
At standup, a dev mentions a bundler statically analyzing a module's import statements to determine which exports are actually used, then removing every unused export from the final bundle. What is this optimization called?
Tree shaking is exactly this: a bundler statically analyzes a module's import and export statements to determine which exports are actually used anywhere in the application, then removes every unused export from the final bundle, relying on the static, analyzable structure of ES module imports to make this determination safely. A hash collision is an unrelated hash-table concept about two keys sharing a bucket. This statically-determine-then-remove-unused-code approach is exactly why tree shaking can shrink a bundle that imports a large utility library down to only the handful of functions actually used.
2 / 5
During a design review, the team switches a utility-library dependency to use ES module imports specifically so the bundler's tree shaking can statically determine which functions are actually used and drop the rest. Which capability does this provide?
Tree shaking here provides a smaller final bundle containing only the code actually used, since statically analyzable ES module imports let the bundler safely determine and remove every unused export instead of including the entire library. Including the entire utility library regardless of import style ships code for functions the application never calls, inflating the bundle unnecessarily. This statically-determine-and-drop-unused behavior is exactly why tree shaking depends on ES module syntax rather than a dynamic module format that can't be analyzed the same way.
3 / 5
In a code review, a dev notices a utility-library dependency is imported using a dynamic, non-statically-analyzable module format, causing the bundler to include the entire library in the final bundle even though the application only calls two of its dozens of functions. What does this represent?
This is a missed tree-shaking opportunity, since switching to statically analyzable ES module imports would let the bundler determine and drop the dozens of unused functions instead of including the entire library. A cache eviction policy is an unrelated concept about discarded cache entries. This non-statically-analyzable-import pattern is exactly the kind of bundle bloat a reviewer flags once only a small fraction of a large library is actually used.
4 / 5
An incident report shows a page's bundle size ballooned after adding a small feature, because the utility library it depended on was imported using a dynamic, non-statically-analyzable module format, forcing the bundler to include the entire library instead of only the functions actually used. What practice would prevent this?
Switching to statically analyzable ES module imports lets tree shaking determine and drop every unused function instead of including the entire library. Continuing to use a dynamic, non-statically-analyzable import format for the utility library regardless of how much the bundle size balloons is exactly what caused the size increase described in this incident. This ES-module-import approach is the standard fix once a dependency is confirmed to block tree shaking with a non-analyzable import format.
5 / 5
During a PR review, a teammate asks why the team relies on tree shaking instead of simply importing only the specific functions needed from a library by hand, path by path, to avoid pulling in the rest. What is the reasoning?
Tree shaking automates determining and removing unused code across the entire dependency graph at build time, while manually importing specific functions path by path requires a developer to know and maintain every such import correctly across the whole codebase, which becomes error-prone and tedious as dependencies change. This is exactly why tree shaking is the standard, automated approach, while manual path-specific imports remain a fragile workaround for libraries that don't support it.