info

Affiliate Disclosure: This article contains benchmarked tools that may compensate us. We only recommend hardware and software tested in our lab environments for maximum LCP and INP efficiency.

Remove Unused CSS & JavaScript in WordPress

Identify and conditionally unload plugin scripts that slow down pages where they are not needed.

calendar_today schedule — min read folder
format_list_bulleted

Table of Contents

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.

mark_email_read

Get Weekly Performance Benchmarks

Join 2,400+ WordPress engineers. Real lab data, no fluff.

No spam. Unsubscribe anytime.

engineering

About the Lab & Author

This benchmark and optimization guide was written by the Performance Engineering team at CoreVitalsLab. With over a decade of experience optimizing high-traffic WooCommerce stores and enterprise WordPress deployments, we focus exclusively on data-driven TTFB reduction, caching architecture, and passing Core Web Vitals.