WooCommerce is one of the most script-heavy WordPress plugins available, loading its full set of front-end assets on every page of the site including blog posts and static pages that contain no commerce functionality. On a typical WooCommerce installation, the plugin enqueues twelve or more stylesheets and scripts unconditionally, adding over 200 KB of combined payload to non-shop pages. The wp_dequeue_script() and wp_dequeue_style() functions remove enqueued handles from the queue before WordPress outputs them, giving complete control over which pages load WooCommerce assets. WooCommerce provides the is_woocommerce(), is_cart(), is_checkout(), and is_account_page() helper functions that return true only on the relevant page types. Dequeuing on pages where these return false removes assets that are genuinely unused, without touching commerce-specific pages where they are required. The is_active_widget() check allows WooCommerce’s mini-cart widget script to stay loaded on pages where the mini-cart sidebar widget is active, preventing a broken experience on hybrid blog-shop sidebars. The woocommerce_enqueue_styles filter provides a cleaner API for WooCommerce-specific stylesheets — returning an empty array disables all of them, while removing individual keys disables only selected stylesheets. Disabling the WooCommerce block styles (wc-blocks-style) separately is necessary on sites that use WooCommerce Blocks on the checkout page. The PurgeCSS and conditional enqueue guide covers the same conditional enqueue pattern for theme stylesheets and should be read alongside this WooCommerce-specific guidance. The deferral post explains how to apply defer to WooCommerce scripts on pages where they must remain loaded but do not need to block rendering. Always test the cart, checkout, account, and any WooCommerce block page after applying these dequeue rules to confirm no required asset was accidentally removed.
Problem: WooCommerce loads its full set of scripts and stylesheets on every page of the site, including blog posts and non-commerce pages where none of those assets are needed, increasing page weight and slowing Time to Interactive.
Solution: Use wp_dequeue_script() and wp_dequeue_style() with WooCommerce conditional functions to remove all WooCommerce front-end assets from pages that have no commerce content, and disable all WooCommerce stylesheets via the filter on shop pages where a custom theme stylesheet replaces them.
// Remove WooCommerce assets from non-commerce pages
add_action('wp_enqueue_scripts', function() {
if (function_exists('is_woocommerce') && is_woocommerce()) return;
if (is_cart() || is_checkout() || is_account_page()) return;
// Dequeue WooCommerce scripts
$wc_scripts = [
'woocommerce', 'wc-add-to-cart', 'wc-cart-fragments',
'wc-single-product', 'jquery-blockui', 'js-cookie',
];
foreach ($wc_scripts as $handle) {
wp_dequeue_script($handle);
wp_deregister_script($handle);
}
// Dequeue WooCommerce styles
$wc_styles = [
'woocommerce-general', 'woocommerce-layout',
'woocommerce-smallscreen', 'wc-blocks-style',
];
foreach ($wc_styles as $handle) {
wp_dequeue_style($handle);
wp_deregister_style($handle);
}
}, 99);
// Alternatively: disable all WooCommerce CSS via filter
// (use when the theme provides its own shop styles)
add_filter('woocommerce_enqueue_styles', function($styles) {
// Return empty array to disable all WooCommerce stylesheets globally
// or unset specific keys: unset($styles['woocommerce-general']);
return [];
});
NOTE: The wc-cart-fragments script fires an AJAX request on every page load to update the mini-cart count — dequeuing it on non-cart pages eliminates a background HTTP request and prevents unnecessary WooCommerce session creation for anonymous visitors.