Whenever you get the 'reduce unused Javacript' warning in lighthoue this means that too much Javacript has been loaded too early during page load.
Fix this issue by removing dead code and defer code that is not immediately needed until it is needed.
- Too many plugins in your CMS.
- Dead code.
- Bad coding.
- Unrestricted tag manager access
- Unnecessary imports
- Code that was loaded immediately but could have been loaded right before use.
However keep in mind that a lighthoue score is not a Core Web Vitals score. The Core Web Vitals are measured with CrUX data.
- Remove unneeded or trivial plugins. If you are using a plugin based CMS like WordPress by far the easiest and most effective method of cleaning up your unused code is to remove plugins that you do not need or that can easily be replaced by a simple code change (for example your analytics plugin, chat plugin, social share plugin)
- Remove dead code. Dead code is code that is not used anymore by the current website. It only takes up space and bandwidth. If you own a website I suggest to schedule a dead code marathon at least twice a year where you take a good look at your custom scripts and remove code that is not needed anymore.
- Remove unnecessary imports (NextJS, React, VUE etc). Most SPA environments are importing too much components / functions. Double check your imports and remove unused code.
- Defer loading of non-critical scripts. Sometimes you need a script (for example, to submit a form) but you do not need it right away. And, let's be honest, 98% of your visitors will not sign up anyway. So for the most part these scripts are unused. It would make more sense to load this script when the visitor interacts with the form, and not during page load.
- Preload more important resources like your fonts and the LCP image element.
I help teams pass the Core Web Vitals:
A slow website is likely to miss out on conversions and revenue. Nearly half of internet searchers don't wait three seconds for a page to load before going to another site. Ask yourself: "Is my site fast enough to convert visitors into customers?"