liveBook · Manning

Dead-code elimination

As explained in React in Depth

Dead-code elimination is a technique that removes code or styles that are unreachable or unused from delivered software.

Dead-code elimination removes unused or unreachable code from delivered software. For stylesheets, it reduces maintenance debt by preventing rules from deleted features from remaining in the application. section 7.1.3

The practical payoff is smaller page-specific payloads: a 100 KB site-wide stylesheet may deliver only 2 KB of relevant styles on one page unless styles are split. Whether removal is automatic depends on the styling approach. section 7.1.3 section 7.3.5

Evaluate the elimination strategy against these trade-offs:

  • Treat code splitting as a delivery optimization: send only the styles required by each part of the website. section 7.1.3
  • Treat maintainability as a removal problem: delete styles left behind after features disappear. section 7.1.3
  • Expect class-name-based styling to require manual dead-code removal because usage cannot be determined automatically. section 7.3.5

A wasted stylesheet payload

A site-wide stylesheet contains 100 KB, while a specific page uses about 2 KB. Code splitting avoids delivering the unused 98 KB to that page. section 7.1.3

How React in Depth covers it

How deep it goes
Explains stylesheet payloads, code splitting, and manual removal, but does not provide an elimination algorithm.
Examples
Uses a 100 KB stylesheet with 2 KB of page-relevant styles to illustrate 98 KB of avoidable delivery.
What you can do after
Evaluate styling approaches for payload size and determine when unused styles require manual removal.
How it connects
Connects dead-code elimination with code splitting, cacheability, maintenance, and class-name-based styling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.