- Unused JavaScript is code that the browser downloads and parses, but that the page does not run while it loads. In WordPress it comes from the theme, the plugins, the blocks and third-party scripts.
- Finding it is easy with Coverage and the Lighthouse audit. The hard part is knowing which scripts serve a click: reduce one script at a time, then check the site.
- In a lab test, loading seven scripts of a store catalog on the first gesture takes the scripts from 17 to 11 and LCP from 2.72 to 2.33 seconds. On the product page the same check does not move LCP.
Nucleo queues only the JavaScript of the blocks on the page, removes scripts where they are not needed and loads the others on the first gesture. The free version works without a key and without an account.
01What unused JavaScript is and where it comes from
Unused JavaScript is code that the browser downloads and parses, but that the page does not run during loading. In WordPress it comes from several sources: the theme, the plugins, the editor blocks and third-party scripts, such as chat, statistics and social buttons.
The cost is paid before the script even runs. The browser must download the file and read it, and a script in the page head, without defer, stops the reading of the HTML until it has finished.
02Find unused JavaScript with Coverage and Lighthouse
The Coverage tool in Chrome DevTools records JavaScript as well as CSS. Open the page in a window without extensions, start Coverage from the command menu and reload the page. The full steps are those of the guide on unused CSS.
Lighthouse, inside DevTools, checks the item Reduce unused JavaScript. For each file it shows the unused bytes and an estimated saving. It lists only the files with at least 20 KiB unused: a page with many small scripts may not appear.
The audit works on one simulated visit. It does not see the scripts that start after a click: for those, use Coverage while you browse the page.
From the command line, nucleo unused-js takes the same measurement in Chromium on several pages and prints the scripts with at least 20 KiB wasted; with --all it prints them all. With Nucleo Pro it saves the result in the asset report, for each template.
- Scroll to the bottom of the page, open the menu, a dropdown, the cart and a form, as a visitor would.
- Click Stop instrumenting coverage and show results, then sort the files by unused bytes.
- Each file shows the share of bytes that did not run: a third-party script often has many.
Learn more: Coverage in Chrome DevTools · Lighthouse: reduce unused JavaScript · Unused CSS in WordPress
03Read the result without being misled
JavaScript that does not run during loading is not necessarily unused. A menu, a form, a cart or a consent window are scripts that the visitor starts with a click. Coverage does not see them until you use them, and Lighthouse reports them as unused.
Before you remove a script, ask what it does and when it starts. The cart script serves the cart page, not the home page.
- Use the page as a visitor would before you decide: click, open, submit a form.
- Check that the script is not a dependency of another one: some plugins load one on behalf of another.
- Repeat the test on several pages of the template, not only the home page.
04Reduce JavaScript without breaking the site
There are three ways, from the simplest to the most invasive. Start with the first: removing a script from the pages that do not use it is safer than editing it.
Defer the script with defer or async. defer runs it after the HTML has been read, in the order in which it appears; async runs it as soon as it is ready, with no order. This applies to scripts with a source file. Use defer for a script that depends on others, and async for an independent one, such as a tracker.
Load the script only on interaction: the chat widget starts when the visitor opens the panel, not on loading. Use this way only after you have checked that the action calls the script.
- Remove the script from the pages that do not use it, by template.
- Defer with defer the scripts that are not needed before the first rendering.
- Load on interaction the scripts that are needed only after a click.
- After each rule, test menus, forms and the cart on desktop and mobile.
05Effect on INP and LCP
A script you do not use has a cost on both measures. On LCP, a script in the head without defer delays the first rendering and, with it, the largest element. On INP, every long task the script runs occupies the main thread and delays the response to clicks.
Removing a script reduces the work, but it does not always move the measures: if the page has another long task, INP stays high. Measure INP with a real interaction, such as a click on the menu, because the lab does not record it.
Check CLS too: a deferred script can delay a banner that then moves the content.
Learn more: What are Core Web Vitals · Core Web Vitals in WordPress
06How Nucleo handles JavaScript
Nucleo loads the JavaScript of only the blocks present on the page: a block you do not use does not bring its script. On theme and plugin scripts it works on the whole file: it removes them from the pages that do not use them, or loads them on the visitor's first gesture. It does not rewrite the content of the files, so it does not remove unused functions inside a script.
The asset rules, included in the free plan, remove, replace or defer a script for each template. With the defer action you choose the strategy: defer, async, interaction or idle. With interaction the script stays on the page as an inert tag and starts on the first touch, key press or scroll. A rule can also match a script printed outside the WordPress queue, by a part of its URL or of its code.
With Nucleo Pro, Nucleo looks for the scripts to delay. From the Performance panel, or with nucleo optimize-js, it opens the page in a browser, delays the candidate scripts and compares the page with the original, before and after a gesture. It publishes only the scripts that do not change the page and do not cause errors. The others stay on loading.
The comparison looks at the page, not at the features: it does not try a payment or a form submission. The cart and the checkout always stay out of the delay.
- nucleo/assets-rules-set sets dequeue, replace, defer and keep rules for a handle, or defer for a script outside the queue.
- nucleo optimize-js tests and publishes the delay for each template. With --replay it repeats the first click inside a selector.
- nucleo unused-js measures the JavaScript that is downloaded and does not run on loading.
- With Nucleo Pro, nucleo/assets-audit starts the asset audit and nucleo/assets-report reads its last result, with the JavaScript bytes for each template.
[
{"action": "defer", "handle": "plugin-x-chat", "strategy": "interaction", "except": ["page:12"]},
{"action": "defer", "src": "widget.example.com/chat.js", "strategy": "interaction"}
]Learn more: Asset optimization · Local CLI · WordPress CLI · Unused CSS plugin for WordPress
07A measured test: from 17 to 11 scripts in the catalog
We measured a demo store: WordPress 7.1.5, the Twenty Twenty-Five 1.5 theme, WooCommerce 11.3.1 and six products with three images each. There are four pages: the home page, a presentation page, the catalog and a product page. Scripts and bytes come from nucleo unused-js, in Chromium 159 at 412×823, with no gestures. FCP and LCP come from Lighthouse 13.6 in mobile emulation: median value of at least five runs for each version.
On the home page and the presentation page, the default rules of Nucleo Pro 0.5.9 for WooCommerce are enough: they remove the store's stylesheets and scripts from the pages that do not use it. The scripts go from 12 to 4 and the JavaScript transferred from 71 to 23 KB. The LCP of the home page goes from 1.96 to 1.54 seconds. The removed stylesheets also help: the render-blocking resources go from 9 to 2. In the free plan you write the same rules by hand, with the dequeue action.
The catalog and the product page need WooCommerce, so the rules remove nothing. This is where the delay works. In the catalog, nucleo optimize-js delayed 7 scripts, jQuery included: 11 remain on loading instead of 17, and the JavaScript transferred goes from 79 to 37 KB. jQuery and jQuery Migrate were in the head without defer and blocked rendering. FCP goes from 1.83 to 1.37 seconds and LCP from 2.72 to 2.33.
On the product page the gain is small. The check delayed 6 scripts out of 12 and left jQuery and the gallery on loading: delaying them changed the page, with 20 differences from the original. The scripts go from 22 to 17 and the JavaScript transferred from 105 to 94 KB. LCP does not improve: 3.24 seconds before and 3.39 after, a difference within the variation between one run and the next.
The test also found a defect that the automatic comparison does not see. With Nucleo 0.5.9, one of the delayed scripts was the one for the gallery magnifier: if the visitor's first gesture was the click on the magnifier, the zoom did not open; on the second click it did. Nucleo 0.5.10 fixes it: it leaves the magnifier on loading together with the gallery, and the zoom opens on the first click. On the same store the scripts on loading become 18 instead of 17 and the JavaScript transferred 98 KB instead of 94. For scripts from other plugins replay remains: nucleo optimize-js --replay "selector" repeats the first click after the scripts have loaded. Adding to the cart worked on the first click on both pages.
After the first gesture, all the delayed scripts of the catalog start in less than a tenth of a second, on a local server. Total Blocking Time is zero in every version. Lighthouse does not report unused JavaScript on any page, before or after: by its estimate no file passes the 20 KiB threshold, and the closest one is jQuery. On a site with heavier third-party scripts the values will be different. Lab measurements from November 27, 2026, on a local demo store. The values change with the theme, the plugins, the content and the server: repeat the measurement on your own site.
| Page | Version | Scripts | JS transferred | JS not run | FCP | LCP |
|---|---|---|---|---|---|---|
| Home | Without Nucleo | 12 | 71 KB | 40 KB | 1.50 s | 1.96 s |
| Home | Nucleo Pro default rules | 4 | 23 KB | 10 KB | 0.94 s | 1.54 s |
| Presentation page | Without Nucleo | 12 | 71 KB | 40 KB | 1.35 s | 2.25 s |
| Presentation page | Nucleo Pro default rules | 4 | 23 KB | 10 KB | 0.95 s | 1.58 s |
| Catalog | Before the delay | 17 | 79 KB | 45 KB | 1.83 s | 2.72 s |
| Catalog | Delay to the first gesture | 11 | 37 KB | 18 KB | 1.37 s | 2.33 s |
| Product page | Before the delay | 22 | 105 KB | 61 KB | 1.94 s | 3.24 s |
| Product page | Delay to the first gesture | 17 | 94 KB | 54 KB | 1.83 s | 3.39 s |
Learn more: WooCommerce integration
08Checklist before you publish
Before you put a change to JavaScript online, check these points on a test copy. If one point fails, undo the last rule and try a smaller change.
- Menus, forms, the cart and buttons work after the change.
- Coverage was run again on the main pages, after using their features.
- The lab CLS stays at 0.1 or below after the change.
- Scripts with the interaction strategy start after an action: try that action on desktop and mobile.
- The gallery, menus and buttons respond even when their click is the first gesture on the page. If the first click is lost, add replay to the rule.
- The quality report does not show blocking problems.