Skip to Main Content
Sustainable Web Design Logo
  • Home
  • Guidelines
  • Emissions
  • Ratings
  • Contact

◂ Web Development guidelines

3.4 Apply Tree Shaking To Code

Web Development

Often when coding, projects can accumulate clutter and functions that are no longer used (due to newer, more effective features being developed). By utilizing tree shaking techniques, all the “dead wood” will be automatically dropped upon compilation, reducing a file’s size.

Criteria

  • Remove Redundancy: Identify and eliminate unused and dead code within CSS and JavaScript.

Impact

Medium

Effort

Medium

Benefits

  • Environmental:
    Removal of unused code eliminates wasted bytes from the rendering tree, which means less wasted download and potential processing time (which can be a battery-draining process).
  • Performance:
    Unused code will not impact visitors, yet it takes up space in the cache, RAM, and takes extra time to download and render. Clearing wasted space frees’ visitor resources.
  • Economic:
    Unused code has a maintenance cost as it might affect other code, additionally, it’s something else for developers to have to deal with unnecessarily.

GRI

  • materials: Medium
  • energy: Medium
  • water: Medium
  • emissions: Medium

Example

  • Code:
    export function read(props) { return props.book }
    import { read } from 'utilities';
    eventHandler = (e) => { read({ book: e.target.value })}
  • Tree Shaking.

Resources

  • Browser Default Styles
  • Coverage: Find unused JavaScript and CSS
  • Front-End Performance 2021: Build Optimizations
  • How large DOM sizes affect interactivity
  • Reduce JavaScript payloads with tree shaking
  • Remove unused CSS
  • The cost of not deleting code
  • Tree shaking
  • Tree-Shaking: A Reference Guide
  • Web Almanac: Sustainability
  • Who Killed My Battery: Analyzing Mobile Browser Energy Consumption (PDF)

View the Guideline

Tags

PerformanceCSSJavaScript

Share

More web development guidelines

3.1 Identify Relevant Technical Indicators

Web Development

3.2 Minify Your HTML, CSS, and JavaScript

Web Development

3.3 Use Code-Splitting Within Projects

Web Development

Learn about W3C’s Sustainable Web Interest Group:

A global community advancing sustainability on the web.

Explore the group

This site is brought to you by

Mightybytes Wholegrain Digital
Website Carbon

This page loaded in 0.25 seconds and emitted just 0.5g of CO2

Visit Website Carbon
Ecograder

How green is your website?

Visit Ecograder
© Copyright Sustainable Web Design 2025. Privacy Policy.