Most WordPress themes and plugins load scripts and stylesheets on all your site’s pages. They load these assets even when they’re not used on the page.
As an example, Contact Form 7 loads its scripts and stylesheets on every page. Its forms may only be used on the contact page, but the assets load on all the pages. Quite unnecessary!
Stripping these unused assets from pages will help you reduce bloat and speed up page load times. WooCommerce and its extensions are susceptible to this issue.
For instance, it’s unnecessary to load scripts related to payment gateways on your store’s homepage or shop page. You can restrict such scripts to load only on the checkout and order confirmation pages. Likewise, eliminate scripts and styles for sliders and carousels from your checkout page.
If you want to know which assets to eliminate, look at the waterfall chart in your website speed test report. It’ll give you an idea about the unnecessary assets that are being loaded.
The Network tab under Chrome browser’s DevTools is also a good place to get started. It’ll give you a comprehensive view of how and what a web page loads.
Strip the scripts and styles that aren’t necessary for the functioning of the page. Start by optimizing your homepage and landing pages, since these are the first points of entry for most of your users.
You can use wp_dequeue_script and wp_dequeue_style functions to remove scripts and styles you don’t need.
Another advantage of eliminating unnecessary CSS and JS assets is that your website will make fewer HTTP requests.