The WooCommerce cart fragments problem (and how to actually fix it)

If you profile almost any WooCommerce store, you’ll find a request to admin-ajax.php firing on every single page — the homepage, blog posts, contact page, everywhere. That’s cart fragments, and it’s one of the most common and least understood drags on WooCommerce performance.

What cart fragments actually do

WooCommerce ships a script called wc-cart-fragments.js. Its job is to keep the little “cart” widget in your header up to date — the item count and total — without reloading the page. To do that, it makes an AJAX call to the server on page load to fetch the current cart state.

Seeing admin-ajax.php on every page? Fixing cart fragments properly is part of every WooCommerce performance engagement I run, along with the server and database work that usually sits next to it. Send me the store's URL if you'd like me to look.

WooCommerce get_refreshed_fragments POST request with a no-store cache header and the JSON reply for an empty cart
The request a classic WooCommerce header cart sends on page load, recorded on our demo shop with the Storefront theme. The cart was empty, and the reply still carried three pieces of cart markup, with a cache-control header that stops any cache from keeping it.

Useful idea. The problem is where it runs: on every page, for every visitor, whether or not there’s a cart widget in sight and whether or not the customer has anything in their cart.

Why it’s slow

Three reasons stack up:

Request waterfall of a WooCommerce content page with the cart fragments POST highlighted at the end
Every request of the demo shop's Sample Page, loaded on an emulated phone. The red bar is the cart fragments POST, 75 ms here on a quiet server with an empty cart, sent once the page has loaded. Under real traffic that round trip goes through PHP and the database on every page view.
  • It’s a POST request to admin-ajax.php, which means it bypasses your full-page cache completely. Every hit goes all the way to PHP and the database.
  • It’s session-based, so it often can’t even use an object cache cleanly.
  • On a loaded server, that round-trip regularly costs 200–500ms, and it competes with the rest of your page for the browser’s attention.

Multiply that across every page view and it’s a meaningful, site-wide tax on speed — and it shows up directly in your Core Web Vitals, particularly interaction responsiveness.

How to fix it properly

The lazy fix you’ll find online is “disable cart fragments everywhere.” Don’t do that blindly — on a lot of themes it breaks the live mini-cart, so the count stops updating when someone adds a product, and now you’ve traded speed for a broken buying experience.

The right approach is surgical:

  • Only load it where it’s needed. Dequeue the script on pages that have no cart interaction (homepage, blog, landing pages) and keep it on shop, product and cart pages. Most visitors land on content pages, so this alone removes the majority of the calls.
  • Update the cart count on add-to-cart instead of on every load. The widget doesn’t need to phone home on page one; it needs to react when the cart actually changes.
  • Make sure your cache respects sessions. If your full-page cache is serving cart pages to everyone, you have a bigger problem than fragments — fix the cache rules too.

Test it, don’t trust it

After any change, add a product from a few different pages and confirm the mini-cart still updates. Then reload a content page and check the network tab — the admin-ajax.php call should be gone there and still present on the shop. That’s the whole game: keep the behaviour, drop the cost.

Small plugin that dequeues wc-cart-fragments, with before and after results for five pages
The exact plugin we tested on the demo shop, and what changed: the call stayed on the shop and product pages and disappeared from the three content pages, two requests fewer on each. Add-to-cart is switched off on the demo, so watching the mini-cart update belongs on a staging copy of the real store.

Cart fragments are rarely the only thing slowing a store down — they’re usually one item on a list. If you want the full picture of where your time goes, start with why your store is slow (and it’s probably not the theme), or let me handle the lot on a performance engagement. Sending me the store’s URL is the quickest way to find out how much this one is costing you.

Got a stuck project?

Send me the URL, the platform, and what’s gone wrong. That’s the whole first step — no call with a stranger required.

Send me a brief