Reduce unused JavaScript

Identify which bundles a visitor actually needs and verify that delayed code still works on the first interaction.

A performance check that reports unused JavaScript is showing code delivered to the tested page but not exercised during that run. It may be obsolete code, or it may support a feature the test never opened. Start by identifying why the page downloads its initial scripts before deciding whether to remove it, split it or load it later.

Separate unnecessary delivery from necessary behaviour

In Sitepulse, note the finding and its estimated savings. The opportunity summary does not include a per-file breakdown. Open the tested page in DevTools, use Coverage to identify unused script bytes, then inspect each script's initiator and its place in the network waterfall. An editor shipped to a read-only page is a strong candidate for route-level separation. A menu handler that runs only after a click needs a different decision.

Choose one script to investigate

Record a realistic session

Start Coverage before reloading, then use search, navigation, forms and consent controls. Repeat at a mobile width and with relevant account permissions. A loading-only run will miss code used later, so do not delete everything shown as unused.

Inspect the production bundle

Use source maps or your build tool's bundle report to locate the module inside a large file. Check whether several versions of a library are included, whether one import pulls in an entire package, or whether a feature is bundled into every route. Keep credentials and other secrets out of browser-delivered code and source maps.

Move features to the point where they are needed

For a client directory, the initial page may only need a list and a search button. The larger export module can be a separate chunk loaded when an authorised user requests an export. Make the waiting state visible and retain error handling if that chunk cannot download. Do not defer code required to validate or complete the first interaction.

For a third-party widget, check whether it needs to run on this route at all. Removing an unused integration is usually more dependable than repeatedly tuning its loading attributes. Confirm the decision with the feature owner before removing behaviour clients rely on.

Verify the transfer and the interaction

Check that the deployed page actually requests fewer or smaller initial scripts. Repeat the performance check under comparable conditions, and try the delayed feature on a slow connection. A smaller initial bundle is not a complete success if the first export or menu interaction now fails.

Do not add the estimated savings from overlapping opportunities as though they were independent. Use Total Blocking Time to investigate loading-time CPU work and INP to investigate interaction delays.

Technical references