How to Reduce Unused CSS and JavaScript in WordPress: Find the Culprits and Fix Them Safely
How to reduce unused CSS and JavaScript in WordPress: find which plugins load files, unload them per page, delay scripts safely and test on mobile.

On this page
- What the warnings mean
- Where unused CSS and JavaScript come from
- How to reduce unused CSS and JavaScript in WordPress
- WooCommerce: be careful with cart and checkout
- Test like your visitors browse
- A worked example: a typical small business site
- When to rebuild instead of patching
- A note on Shopify
- Quick check: how much unused code loads?
- When to get help
- FAQs
- The "reduce unused CSS" and "reduce unused JavaScript" warnings usually come from plugins, page builders and themes loading files on pages that do not need them.
- Start by removing plugins you do not need, then unload files per page, delay non-essential scripts and generate critical CSS, testing each change.
- Measure on a real mid-range phone and with field data, not just a lab score, and keep a backup and staging copy before making aggressive changes.
To reduce unused CSS and JavaScript in WordPress, first find out which plugins, theme files and third-party scripts are loading on each page, then stop loading the ones a page does not use. In practice that means removing unnecessary plugins, unloading plugin files on pages where they are not needed, delaying non-essential scripts such as chat widgets and trackers, and using critical CSS so the page can display before the full stylesheet loads. Test every change, because removing the wrong file can break forms, sliders or checkout.
This guide explains where the warnings come from, the safe order to fix them in and how to check that the changes actually make the site faster for visitors in India.
What the warnings mean
PageSpeed Insights and Lighthouse show "Reduce unused CSS" and "Reduce unused JavaScript" when a page downloads code that it does not use while loading. Every extra file takes time to download, parse and run, which matters most on mid-range Android phones and patchy mobile data. Unused JavaScript also keeps the phone's processor busy, which can make the page feel slow to respond to taps.
The figures in these reports are estimates. Some "unused" code is needed later, for example when a menu opens or a form is submitted. The goal is not to reach zero, but to stop loading code where it clearly does not belong.
Where unused CSS and JavaScript come from
| Source | Typical example | Usual fix |
|---|---|---|
| Plugins loading everywhere | A contact form plugin loading its files on every blog post | Unload on pages without a form |
| Page builders | Full builder libraries on simple pages | Builder performance settings, fewer widgets |
| Multipurpose themes | Styles for dozens of layouts you never use | Theme performance options or a lighter theme |
| Sliders and animations | Slider scripts on every page because one page uses them | Remove or load only where needed |
| Third-party scripts | Chat widgets, trackers, review widgets, social embeds | Remove unused ones, delay the rest |
| WooCommerce | Cart scripts on non-shop pages | Limit to shop, cart and checkout where safe |
| Fonts and icon libraries | A full icon font for a handful of icons | Use only the icons you need, or SVG |
How to reduce unused CSS and JavaScript in WordPress
1. Back up and use a staging copy
Some of these changes can break layouts or features. Take a full backup and, ideally, test on a staging copy first. Many Indian hosting plans include one-click staging.
2. Find what loads on each page
Open the PageSpeed Insights report and expand the unused CSS and JavaScript sections to see the file names. Most show the plugin or theme folder in the path, which tells you where the code comes from. The Coverage tab in Chrome developer tools shows how much of each file is used on that page.
3. Remove plugins you do not need
The cleanest fix is removing a plugin entirely. Look for plugins that duplicate each other, features you tried once and forgot, and plugins that add a small effect that could be done with a few lines of CSS. The guide to essential WordPress plugins for business helps decide what to keep.
4. Unload files per page
Asset management plugins and some performance plugins let you disable specific CSS and JavaScript files on chosen pages or post types. For example, you can load the form plugin only on the contact page, or the slider only on the home page. Make one change at a time and test the affected pages.
5. Delay non-essential JavaScript
Chat widgets, analytics, heatmaps and social embeds rarely need to load before the visitor sees the page. Many caching and performance plugins can delay these scripts until the visitor interacts with the page. Test carefully: delaying the wrong script can stop menus, forms or tracking from working.
6. Generate critical CSS
Critical CSS is the small set of styles needed for the top of the page. Some performance plugins generate it automatically and load the rest of the stylesheet later. This addresses render-blocking as well. See eliminating render-blocking resources for more.
7. Use page builder and theme performance settings
Many builders and themes now include options to load only the CSS and JavaScript for the widgets used on each page, to disable unused features and to stop loading icon libraries or fonts you do not use. Turn these on, regenerate CSS and clear caches.
8. Clear caches and retest
After each change, clear your caching plugin, server cache and CDN, then rerun PageSpeed Insights and check the key pages by hand: home, a service page, a blog post, the contact form, and for stores, product, cart and checkout.
WooCommerce: be careful with cart and checkout
WooCommerce loads scripts for the mini cart, cart fragments and checkout. Unloading them on non-shop pages can help, but the cart count in the header may stop updating, and checkout must never be touched carelessly. Payment gateway scripts such as Razorpay or other Indian gateways need to load on checkout. Always place a test order after changes. The WooCommerce speed optimisation guide covers store-specific tips.
Test like your visitors browse
A high lab score on a fast office connection does not mean the site feels fast to a visitor on a mid-range phone on mobile data. Check:
- The field data section of PageSpeed Insights, if your site has enough traffic.
- Core Web Vitals in Google Search Console. See Core Web Vitals explained.
- A real phone on mobile data, opening the main pages and tapping menus and buttons.
The guide on website speed on Indian mobile networks explains why these checks matter.
A worked example: a typical small business site
Consider a common setup for a small business in India: a multipurpose theme, a page builder, a contact form plugin, a slider on the home page, a WhatsApp chat widget, a Google reviews widget, analytics and a Meta pixel. On a simple blog post, the page may load the slider, the form, the reviews widget and the full builder library, even though none of them appear on it.
A sensible clean-up for that site might look like this:
- Replace the home page slider with a single, well-optimised hero image and remove the slider plugin.
- Load the contact form plugin only on the contact page and the pages that actually contain a form.
- Load the reviews widget only on the home and service pages where reviews are shown, or replace it with a few manually quoted reviews.
- Delay the chat widget, analytics and pixel until the visitor scrolls or taps, after checking that tracking still records correctly.
- Turn on the builder's option to load only the assets used on each page, and stop loading icon fonts that are not used.
- Generate critical CSS, clear caches and retest the main page types on a phone.
None of these steps needs custom code, and each can be undone if something breaks. The order matters: removing whole plugins first means less to tune later. Keep a short note of each change and the date, so if a form or tracking issue appears weeks later, you know where to look.
When to rebuild instead of patching
If a site runs a heavy multipurpose theme with a page builder, several sliders and dozens of plugins, unloading files one by one can only go so far. Sometimes a lighter theme or a cleaner rebuild of key pages gives a better result with less ongoing tuning. That is a bigger decision, so measure first and weigh the cost of a rebuild against how much speed matters for your enquiries or sales.
A note on Shopify
Shopify stores see the same warnings, usually from apps that inject scripts on every page and from leftover code of uninstalled apps. The fix follows the same logic: remove apps you do not use, check the theme for leftover snippets and choose a lean theme. See the Shopify store slow fix guide for details.
Quick check: how much unused code loads?
- Use Coverage: in Chrome press F12, then Ctrl+Shift+P, type "Coverage" and reload the page. The red part of each bar is code that was not used.
- Read PageSpeed: run the page through PageSpeed Insights and open "Reduce unused CSS" and "Reduce unused JavaScript". Note which files cost the most.
- Find the source: match each file path to a plugin folder, such as
/wp-content/plugins/plugin-name/, to see which plugin loads it.
Fonts are often part of the problem too: see how to reduce font load on a WordPress site.
When to get help
Get help when removing code breaks menus or forms, when a page builder loads most of the unused code, or when scores stay red after trying plugins. WordPress speed optimisation removes unused code safely with testing, and Elementor development helps with builder-heavy sites. Get in touch with your page URL.
FAQs
How do I reduce unused CSS and JavaScript in WordPress?
Remove plugins you do not need, unload plugin files on pages that do not use them, delay non-essential scripts, generate critical CSS and use your theme or builder's performance settings, testing after each change.
Can I get the unused CSS warning to zero?
Rarely, and it is not necessary. Some code is needed after the page loads. Focus on removing files that clearly do not belong on a page.
Will unloading plugin files break my site?
It can if a file is needed. Change one thing at a time, test the affected pages and keep a backup or staging copy.
Is delaying JavaScript safe?
Usually for chat, analytics and social widgets. Delaying menu, form or checkout scripts can break them, so exclude those and test.
Does reducing unused JavaScript help Core Web Vitals?
It often helps, especially responsiveness and loading on slower phones, but results depend on what else is slowing the page.
Need help with your website?
I'm a freelance WordPress developer building fast, SEO-friendly websites since 2020. Tell me what you need and I'll reply with a plan and a fixed quote, usually within 24 hours.


