Skip to content

How to reduce unused JavaScript

Speed1 min readFixes check unused-js

JavaScript that is downloaded but never runs still costs bandwidth, parsing and memory on phones. Split bundles, drop dead plugins and load features on demand.

Step by step, with screenshots: async vs defer: loading JavaScript without blocking the page →

Check your own site

Runs this check and the other 192, free, in about 45 seconds.

Or run only this check with the free Unused CSS/JS checker.

What it is

Unused JavaScript is code that a page downloads but does not run while the page loads. It comes from large bundles that include every feature of a site, plugins that load their scripts on every page, and third-party tags such as analytics, ads and chat widgets.

JavaScript is the most expensive resource per byte: it has to be downloaded, parsed and compiled, often on a slow phone, even when it never runs. Lighthouse flags scripts with more than 20 KiB unused, and getReport shows the savings in bytes and time. A page is OK when the scripts it loads up front are the ones it needs to work, and everything else loads on demand or not at all.

What a passing site looks like

  • Little unused JavaScript is downloadedwarning · −4 ptseffort M

Unused JavaScript

Why it matters. JavaScript is the most expensive thing a page loads: it must be downloaded, parsed and run. Code that never executes still costs all of that on a phone.

How to fix it.
  1. Delay third-party scripts until interaction (WP Rocket "Delay JavaScript", Shopify: audit installed apps).
  2. Code-split large bundles so each page loads only its own code.
  3. Remove plugins, apps and tags you no longer use.

Questions people ask

How do I reduce unused JavaScript in WordPress?

Remove plugins you do not use, then stop the rest loading scripts on pages that do not need them, with a plugin such as Perfmatters or Asset CleanUp. Delay non-essential scripts such as chat, social embeds and marketing tags until the visitor interacts, which WP Rocket, LiteSpeed Cache and similar plugins can do. Test forms and checkout after each change.

How do I reduce unused JavaScript?

Split your code so each page loads only what it uses, load features such as maps, video players and carousels when they are needed, and remove old libraries the site no longer depends on. Audit third-party tags too: each analytics, ads or chat script adds code you do not control. The report lists the scripts with the most unused bytes.

How do I find unused JavaScript?

In Chrome DevTools, open the Coverage panel (Ctrl+Shift+P, then Show Coverage), reload the page and sort by unused bytes. Red bars show code that did not run. Lighthouse and getReport list the same scripts with estimated savings. Code that runs only after a click also looks unused during load, so decide whether to load it later rather than delete it.

Does Google Tag Manager cause unused JavaScript?

Often, yes. The GTM container and the tags it loads, such as analytics, ad pixels and heatmaps, show up as unused JavaScript because much of their code runs only on certain events. Remove tags nobody uses, fire tags only on the pages that need them, and avoid loading the same tracking script twice, once through GTM and once through the theme.

Filed under Speed & Core Web Vitals. Copy is generated from the same catalogue that scores every report, so what you read here is what the report says.