---
title: "Tech Tip #31: Ship less JavaScript"
description: "Every page loads your whole app's JavaScript. Why?"
url: https://greencode.ai/tech-tips/31-ship-less-javascript/
---

# Tech Tip #31: Ship less JavaScript

**Every page loads your whole app's JavaScript. Why?**

[Watch the video](https://media.greencode.ai/shorts/ship-less-javascript-6c0d636b6b73.mp4)

Video created by [explainapaper.com](https://explainapaper.com/?utm_source=greencode.ai&utm_medium=film&utm_campaign=made-by)

### The problem

Bundles grow until every page downloads, parses and runs code for features it never shows. Parsing and executing JavaScript costs processor time on every visitor's device.

### The fix you can use today

- Code-split so each page loads only what it uses.
- Tree-shake and remove unused libraries; check for duplicate copies.
- Load third-party tags only when needed, for example after consent.

GreenCode researchers list big JavaScript bundles as a waste. GreenCode's own site loads scripts only where they are needed.

### Tools that help

- [GreenCode Constitution skill](https://greencode-constitution.org/?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode) (GreenCode researchers): open-source energy principles and a catalogue of 37 energy anti-patterns that an AI coding agent can follow to find and fix waste like this
- [Lighthouse](https://developer.chrome.com/docs/lighthouse/overview?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode): audits a page for total byte weight, unused JavaScript and CSS, image formats and offscreen images
- [WebPageTest](https://www.webpagetest.org/?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode): loads a real page and shows every request, its size and when it loaded

### How GreenCode helps

GreenCode helps tackle this by loading scripts on greencode.ai only on the pages that use them. With WebP images, purged styles and one self-hosted font, that cut the home page's first view from 80 requests to 33. [More on this](https://greencode.ai/green-hosting/).

### Tags

#javascript#web-performance#frontend

### Sources

- [GreenCode Constitution skill, energy anti-patterns: N5 bloated client bundles: tree-shake, code-split, lazy-load](https://greencode-constitution.org/skill.md?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode)
- [Green hosting: scripts loaded only on pages that use them; analytics and ad tags held until consent](https://greencode.ai/green-hosting/)
- [Green Software Foundation, Green Software Patterns: Remove unused CSS definitions](https://github.com/Green-Software-Foundation/patterns/blob/main/docs/development/media-and-code-efficiency/remove-unused-css.md?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode)
- [Sustainable Web Design, Guideline 3.3: split bandwidth-heavy components into on-demand modules](https://sustainablewebdesign.org/guidelines/3-3-modularize-bandwidth-heavy-components/?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode)
- [W3C, Web Sustainability Guidelines: split bandwidth-heavy components into modules loaded when needed](https://www.w3.org/TR/web-sustainability-guidelines/#code-splitting)
- [W3C, Web Sustainability Guidelines: load non-essential assets asynchronously or deferred](https://www.w3.org/TR/web-sustainability-guidelines/#asynchronous-code)

[All GreenCode Tech Tips](https://greencode.ai/tech-tips/)

#### Key Facts

- Tip **#31**
- For **Developers**
- Category **Web and front-end**
- Format **short video**
![GreenCode](https://greencode.ai/wp-content/uploads/2024/12/greencode-logo-website-small-colours-2.webp)

Want this checked on your own system? Talk to the GreenCode team.

[Get in touch](https://greencode.ai/contact/)
