Performance
Unused JavaScript
Unused JavaScript is script code the browser downloaded and parsed but did not run during the page load. It adds bytes and CPU time without doing anything.
How it is measured
Chrome DevTools Coverage shows each script's used and unused bytes after a reload. Lighthouse's 'Reduce unused JavaScript' flags files with at least 20 KB unused and estimates savings, though only for the load itself.
'Unused' means not executed yet. Code behind a click may be needed later. Separate reachable code from dead code: the first can be split and loaded on demand, and the second can be deleted.
Worked example
A SaaS marketing page ships a 1.1 MB main bundle. Coverage says 72% is unused at load: a rich-text editor (310 KB), a date picker (96 KB), and an admin panel (240 KB) that anonymous visitors cannot use. Moving those into dynamic imports cuts the initial bundle to 460 KB.
On a throttled phone, script evaluation falls from 2.4 s to 0.9 s.
How it differs
Unused JavaScript measures waste inside scripts. Page weight is the total of everything. A page can weigh little and still carry waste in script, and heavy images can dominate weight with zero unused JS. Unused JS also costs CPU, which weight does not count.
Common errors
Deleting code that is used on interaction. Measuring only one scenario. Ignoring third-party contributions. Assuming minification fixes it. Leaving dead feature flags in place. Testing while logged in with DevTools open.
In practice
Run Coverage on a logged-out load of your top page. Sort scripts by unused bytes, split the first large chunk by route or interaction, and delete flagged dead code. Rebuild, then confirm the bundle shrank in the analyzer and that TBT improved in Lighthouse.