Performance · JavaScript and CSS
Unused JavaScript
This page loads a 72KB script library but calls only one of its 600 functions, so almost all of the downloaded code is never run.
How this page is built
The page loads unused.js, a minified library of 600 small functions that each return a colour code. Only the first function is called, and it writes the code below. The other 599 are downloaded and parsed, then never run.
Colour code from the library: loading
Why it matters
Every byte of JavaScript has to be downloaded, parsed and compiled, even when it never runs. On a slow phone that work competes with everything else the page needs to do, so code that is never used still makes the page slower to load and to respond.
Unused code usually comes from large libraries included for one feature, scripts that load on every page but are needed on only a few, or features that were removed while their code stayed behind.
How to check it
Run Lighthouse or PageSpeed Insights on the page and look at the diagnostics. Crawl tools that run Lighthouse for each page, or that measure page resources, report the same finding across the site. Lighthouse lists each script with a large amount of unused code and the possible saving. The Coverage panel in Chrome’s developer tools shows which lines ran.
How to fix it
Load only the code each page needs. Split bundles by page or feature, load rarely used features on demand with dynamic imports, and remove libraries that are no longer needed. Tree shaking in a bundler drops exports that nothing imports.