Reduce unused JavaScript
The Reduce unused JavaScript diagnostic comes up when PageSpeed detects unused JavaScript that's slowing down your site.
Reduce unused JavaScript and defer loading scripts until they are required to decrease bytes consumed by network activity. Learn how to reduce unused JavaScript.
Understanding reduce unused JavaScript
Plugins and themes have to load CSS and JavaScript on your pages to do their jobs: a slider at the top of your homepage, a form on the contact page, a gallery with animations, etc.
The problem is that all these scripts are loaded on all other pages, even when there’s no need, and this is unnecessarily slowing down the speed of your pages.
PageSpeed will trigger this recommendation for all JavaScript files with more than 20KB of unused code.
How to reduce unused JavaScript
WP Rocket can't remove the unused JavaScript from your site. However, the problematic JavaScript files can be optimized by the following feature:
- Delay JavaScript execution - To delay the execution of the JavaScript files with unused code.
Alternatively, the following plugins can help you to minimize unused JavaScript from your pages. Please use them with care and consult your developer if you need help.
But the only way to truly satisfy any recommendation about removing unused JavaScript is to fully custom-code a theme/plugin with page-level JavaScript.
