Every WordPress plugin ships JavaScript whether you need it on a given page or not. Use wp_dequeue_script() to conditionally remove scripts on pages where they are not needed. This reduces Total Blocking Time and improves INP scores.
How to audit unused JavaScript
Open Chrome DevTools Coverage panel (Ctrl+Shift+P → Coverage) to see exactly how much of each script is executed on each page. Sort by Unused Bytes to find the worst offenders.
Conditionally dequeue scripts
add_action("wp_enqueue_scripts", "dequeue_unused", 100);\nfunction dequeue_unused() {\n if (!is_page("contact")) {\n wp_dequeue_script("contact-form-7");\n }\n if (!is_woocommerce()) {\n wp_dequeue_script("wc-cart-fragments");\n }\n}
Expected gains
Removing unused scripts can reduce TBT by 100–500ms and cut JavaScript payload by 50–300KB per page.