Performance Tutorial Intermediate 4 min

Speed Up WooCommerce: Stop Loading Its Scripts and Styles on Pages That Don’t Sell

WooCommerce loads its CSS and JavaScript on every page, including blog posts that sell nothing. Here's what it loads, what you can safely remove, and the three pages you must never touch.

TutorialIntermediate10 minTested on WordPress 7.1Updated November 13, 2026

A blog post on a WooCommerce site often ships the shop’s CSS and JavaScript to readers who will never see a product. It isn’t much per file, but it is on almost every visit, and it is work the browser has to do before the page settles. On content-heavy stores, that is most of your traffic.

This guide shows what WooCommerce actually loads (checked against WooCommerce 11.3), what is safe to remove, and how to do it without breaking checkout.

What WooCommerce loads on every page

Open any non-shop page, view the source and search for woocommerce. On a typical site you will find these:

FileEvery pageOnly where needed
woocommerce-general, -layout, -smallscreen (classic themes)YesNo
woocommerce-blocktheme (block themes)YesNo
woocommerce (woocommerce.js)YesNo
wc-add-to-cart (when AJAX add to cart is on)YesNo
sourcebuster-js + wc-order-attributionYesNo
wc-cart-fragmentsNoOnly with the Cart widget
wc-cart, wc-checkout, wc-single-productNoYes

The good news: WooCommerce already keeps the heavy cart, checkout and product-gallery scripts to the pages that use them, and since WooCommerce 7.8 the cart fragments script only loads where the classic Cart widget is used. What is left on every page is the main stylesheets, woocommerce.js and the add-to-cart script.

Measure first

Open your browser’s developer tools, go to the Network tab, reload a blog post and filter by woocommerce. Note the number of requests and their size. You will compare against this at the end.

Before you start

  • A way to add PHP snippetsA child theme’s functions.php, a must-use plugin or a code snippets plugin
  • A backup or staging siteSo you can test checkout safely
  • A list of pages that sellIncluding landing pages with product blocks or shortcodes

Remove WooCommerce files from pages that don’t sell

  1. Add the snippet

    This snippet from our library runs after WooCommerce has queued its files. On shop, product, category, cart, checkout and account pages, and on any page with WooCommerce blocks or product shortcodes, it changes nothing. Everywhere else it removes the stylesheets, block styles and the add-to-cart and cart fragments scripts.

    functions.phpPHP
    add_action( 'wp_enqueue_scripts', function (): void {
    	// Do nothing if WooCommerce isn't active.
    	if ( ! function_exists( 'is_woocommerce' ) ) {
    		return;
    	}
    
    	// Keep everything on store pages.
    	if ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) {
    		return;
    	}
    
    	// Keep everything on pages that contain WooCommerce blocks or shortcodes.
    	$post = get_post();
    	if ( $post && ( str_contains( $post->post_content, 'wp:woocommerce/' ) || has_shortcode( $post->post_content, 'products' ) || has_shortcode( $post->post_content, 'product_page' ) ) ) {
    		return;
    	}
    
    	foreach ( [ 'woocommerce-general', 'woocommerce-layout', 'woocommerce-smallscreen', 'woocommerce-inline', 'wc-blocks-style' ] as $style ) {
    		wp_dequeue_style( $style );
    	}
    	foreach ( [ 'woocommerce', 'wc-add-to-cart', 'wc-cart-fragments' ] as $script ) {
    		wp_dequeue_script( $script );
    	}
    }, 99 );
    Tested on WordPress 7.1 · PHP 8.3Checked November 13, 2026

    It checks that WooCommerce is active first, so deactivating WooCommerce later won’t take your site down.

  2. Leave order attribution alone

    sourcebuster-js and wc-order-attribution look like the kind of script you would remove, but they record which page and campaign a visitor arrived from. If a reader lands on a blog post and buys later, WooCommerce only knows the post sent them because those scripts ran on it. The snippet keeps them on purpose.

    Don't use order attribution at all?

    Turn it off properly instead of removing the scripts: WooCommerce → Settings → Advanced → Features, then untick Order attribution. WooCommerce then stops loading both scripts everywhere.

  3. Theme styles WooCommerce itself? Turn its CSS off everywhere

    Some themes, and most page builders, ship their own complete WooCommerce styling. In that case WooCommerce’s stylesheets are only overridden, never used, and you can switch them off on every page:

    functions.phpPHP
    // Only if your theme styles the shop, cart and checkout itself.
    add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
    Tested on WordPress 7.1 · PHP 8.3Add to: your child theme's functions.phpChecked November 13, 2026

    Check the shop, a product, the cart and checkout afterwards. If buttons or the checkout form look broken, your theme relies on WooCommerce’s CSS: remove this line and use only the snippet above.

You should now see

On a blog post, the Network tab no longer lists woocommerce-general, woocommerce-layout or wc-add-to-cart. On the shop, product pages, cart and checkout, everything still loads and works.

Something broke after adding the snippet3 common fixes
  • The mini-cart count in the header is wrong on blog posts. It updates through cart fragments. Either accept the count from page load, or add the pages with a mini-cart to the snippet’s list of store pages.
  • A landing page with a product grid looks unstyled. Products added through a template part, such as the footer, aren’t detected. Add that page’s check to the snippet.
  • Add to cart does nothing on a custom page. The page sells, so it needs the scripts. Add it to the store pages in the snippet.

The three pages you must never strip

Whatever you change, the cart, checkout and My Account pages need every WooCommerce file. They validate addresses, update totals, take payments and handle logins with that JavaScript. The snippet already leaves them alone. If you write your own version, start from is_cart() || is_checkout() || is_account_page() and return early.

Check the result

Run the same test as at the start: reload a blog post with the Network tab open and filter by woocommerce. You should see fewer requests and a smaller total. Then place a test order from a product page to the thank-you page, so you know the store side is untouched.

If you use a page cache, clear it first, or you will be measuring the old page.

Check your understanding

1Which two scripts should stay on blog posts so marketing reports stay accurate?
2When is it safe to return an empty array from woocommerce_enqueue_styles?

Was this helpful?

Written by Nahnu Plugins

We build and maintain WordPress plugins. Every guide is tested on a fresh WordPress site before it goes out, and checked again when WordPress updates.

More guides

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only