Horizontal banner with bold white text reading 'Optimizing WooCommerce CPU Usage' on a deep purple gradient background, paired with the white WooCommerce logo, illustrating an expert tutorial on minimizing server CPU load for better eCommerce speed and stability.

Optimizing WooCommerce CPU Usage

Boost WooCommerce speed by disabling Cart Fragments.

5 min read

How to Disable WooCommerce Cart Fragments for Better Performance

WooCommerce is a fantastic platform for building online stores, but sometimes, default features designed for convenience can unintentionally slow down your website. One common culprit is the “Cart Fragments” AJAX request. While it serves a purpose, it often runs unnecessarily and can significantly impact your site’s loading speed. Let’s dive into what it is, why it can be problematic, and how you can disable it for a faster store.

What is the WooCommerce Cart Fragments AJAX Call?

Have you noticed how on many WooCommerce stores, the mini-cart icon in the header updates automatically when you add a product, without needing a full page refresh? That’s the Cart Fragments feature in action.

Technically, WooCommerce uses an AJAX (Asynchronous JavaScript and XML) call, specifically ?wc-ajax=get_refreshed_fragments, to fetch the latest cart contents (like the item count and subtotal) and update the mini-cart display dynamically.

Why Can Cart Fragments Slow Down Your Site?

While dynamic updates sound great, the implementation of Cart Fragments has a few significant performance drawbacks:

  • It runs on (almost) every page: This AJAX request is typically triggered on every single page load across your WordPress site, not just shop-related pages. Even your blog posts, contact page, or homepage might be making this call in the background.

  • It bypasses caching: Because the cart content needs to be fresh, this AJAX request is often configured not to be cached by standard page caching systems (like those used by hosting providers or caching plugins). This means it hits your server directly every time.

  • It adds server load: Each uncached request consumes server resources (CPU, memory). On high-traffic sites, or even moderately busy ones, these frequent calls can add up, slowing down response times for all users.

  • It impacts Core Web Vitals: A slow, uncached AJAX call firing on page load can negatively affect metrics like Time To First Byte (TTFB) and potentially Largest Contentful Paint (LCP), which are crucial for user experience and SEO.

How to Check if Cart Fragments is Impacting You

You can easily check the impact of this request using your browser’s developer tools:

  1. Right-click anywhere on your site and select “Inspect” or “Inspect Element”.
  2. Go to the “Network” tab.
  3. Reload the page (you might need to do a hard refresh - Ctrl+Shift+R or Cmd+Shift+R).
  4. Look for a request containing ?wc-ajax=get_refreshed_fragments.
  5. Check its loading time in the “Time” or “Waterfall” column. If it’s taking several hundred milliseconds or more, it’s likely contributing to slower page loads. Check this on various page types (homepage, product page, blog post).

The Solution: Disabling Cart Fragments

💡 Easiest Method: Use a Plugin For the simplest approach, you can use the Disable Cart Fragments plugin by Optimocha. This lightweight plugin effectively disables cart fragments while the cart is empty, but enables it when needed. Simply install, activate, and you’re done - no coding required!

If you prefer not to use a plugin, you can accomplish the same result by adding a small PHP code snippet to your site. This gives you more control and reduces the number of plugins on your site.

💡 Where to Add Code: The safest way to add PHP snippets is using a dedicated plugin like Code Snippets or by adding it to your child theme’s functions.php file. Avoid editing your main theme’s files directly, as changes will be lost upon theme updates.

Here’s the code snippet to disable the Cart Fragments AJAX call:

<?php
add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments_script', 11 );
function dequeue_woocommerce_cart_fragments_script() {
    wp_dequeue_script( 'wc-cart-fragments' );
}
?>

Understanding the Trade-off

⚠️ Important Consequence: Disabling this script means your mini-cart (often in the header) will not update immediately when a customer adds an item to the cart using AJAX buttons on the same page. The cart will update correctly once the customer navigates to a new page, including the main Cart page or Checkout page. The core cart functionality remains unaffected.

For many stores, this trade-off is acceptable. Users typically proceed to the cart or checkout page after adding items, where they’ll see the updated information. The performance gain across the entire site often outweighs the slight change in mini-cart behaviour.

Should You Disable Cart Fragments?

Consider disabling Cart Fragments if:

  • Your website performance is suffering, and tests show the get_refreshed_fragments call is slow.
  • Instant mini-cart updates are not critical to your user experience.
  • You prioritize overall site speed and reduced server load.
  • Your theme perhaps offers alternative ways to display cart counts or doesn’t rely heavily on the dynamic mini-cart.

Test Before and After!

Whenever you make changes like this, it’s crucial to test:

  1. Speed Tests: Run speed tests (using tools like GTmetrix, PageSpeed Insights) before and after adding the code snippet to measure the performance improvement. Pay attention to TTFB and overall load times.

  2. Functionality Tests: Thoroughly test your add-to-cart process. Ensure items are added correctly, and the main cart and checkout pages display the right information.

Conclusion

The WooCommerce Cart Fragments AJAX call is a well-intentioned feature that can unfortunately become a performance bottleneck. By understanding its purpose and impact, you can make an informed decision about whether disabling it is right for your store. Adding a simple code snippet can often lead to significant speed improvements across your entire site, improving user experience and potentially boosting your SEO rankings. Just remember to test carefully after implementing the change!

Share this post

Ready to Get Started?

Join thousands of satisfied customers who trust us with their web hosting needs. Get blazing-fast performance, 24/7 support, and enterprise-grade security for your website today.

Related Articles

Continue reading with these related posts

Banner image with a bold white title 'Speed Up Your WordPress Site on a Budget' on a dark blue gradient background, featuring the classic white WordPress logo, representing a cost-effective guide for faster website performance and lower hosting costs.

How to Speed Up Your WordPress Site on a Budget (7 Easy Wins)

Improve your WordPress site speed without spending a fortune. Discover 7 easy, budget friendly tips to make your WordPress website load quicker. Boost performance and user satisfaction today.

WordPress Performance
June 23, 2025
Read more
Illustration featuring a blue background with a network globe icon and the title 'How Anycast DNS Made Our Hosting Faster & Smarter'—highlighting DNS-based hosting improvements through Anycast routing for improved speed, resilience, and smart traffic distribution.

How Anycast DNS Made Our Hosting Faster, Smarter, and More Resilient

From 400ms to sub-10ms DNS: How SpeedyPage rebuilt its infrastructure to deliver instant lookups around the world—transparently.

Performance News Hosting
June 25, 2025
Read more
Header image for blog post about SpeedyPage's bandwidth pricing

Introducing Global Bandwidth Pricing & On-Demand Traffic Blocks

From tickets to instant bandwidth: How we simplified global traffic scaling with one flat rate and zero manual steps, globally.

News Servers
July 27, 2025
Read more

Comments

Join the discussion and share your thoughts

Leave a Comment

Your comment will be reviewed before being published

Your email will not be published

Please be respectful and constructive

0/2000
B
Benji

Excellent advice!