WooCommerce cart fragments is a script that, on every page view, asks the server for the current cart contents and swaps the counter in the header. It sounds harmless, but that request goes through PHP and the database, so it bypasses the page cache. The result: a cached page opens quickly, yet the store still does work on every view, including on the blog and the contact page.
Below I describe how to recognise it in your own store, why the mechanism exists at all, when it really hurts and how to disable it so the cart keeps working. I start with diagnosis, because switching things off blindly ends with a broken counter and a call from a customer.
What WooCommerce cart fragments do
WooCommerce serves many pages from cache, yet a cart is personal: every visitor has something different in it. To keep the header counter truthful despite caching, WooCommerce loads a cart-fragments script. It sends an AJAX request, receives ready-made pieces of HTML from the server (hence “fragments”) and drops them in place of the mini-cart.
The fragments are also remembered in the browser, so the next page can show the last known state at once. Even so, the script usually confirms that state with a request to the server. That request is a POST, so the page cache will not answer it.
The mechanism makes sense where the cart is visible and has to be exact. The trouble starts when it runs everywhere while the header counter is useless on most pages. That depends on the store, so I do not quote any average here.
How to spot cart fragments in the Network tab
Open the store in a logged-out window, open the browser tools (F12), go to the Network tab and reload the home page. Type get_refreshed_fragments in the filter box. If you see a request like ?wc-ajax=get_refreshed_fragments, cart fragments are running on that page.
This distinction matters, because problem reports often say “admin-ajax on every page”. admin-ajax.php is a shared gateway used by many plugins, while cart fragments use their own wc-ajax address. So also type admin-ajax in the filter and check separately who else is polling the server. There can be several culprits, and this article covers only one of them.
What to read from that request:
- Server response time (the Time column or the Timing tab, “Waiting for server response”). If the request is slow, every page view waits on the server.
- When it fires. If it runs on the home page, the blog and the contact page, not only on the cart, that is the classic symptom.
- Whether it blocks anything visible. The request itself runs in the background, but a congested server slows the rest as well.
The same check tells you one more thing: whether the store has page caching at all. When the page itself comes back in a fraction of a second and the fragments request takes several times longer, you can see where the bottleneck sits.
When cart fragments really hurt
They are not always a problem. On a fast server with modest traffic the request returns so quickly that nobody notices. They hurt in three situations.
A slow server or busy PHP. Every page view starts an extra process. As traffic grows, so does the number of these requests, because there is one per page view. At a peak, for example during a promotion, that adds load exactly when the store matters most.
A heavy page with many scripts. The browser has one thread for computing. If at the moment of the click it is busy with plugin scripts and the cart fragments response, the click waits. That is what a poor INP looks like, meaning the response to a click, and the article on Core Web Vitals in WooCommerce covers it too.
No sensible caching. When pages are generated every time anyway, one more request makes little difference. When caching works and cart fragments stay, they become the biggest remaining cost on pages that should be almost free. I write about caching without breaking the cart in the article on WordPress caching.
How to measure before you disable anything
Measure the state before the change, otherwise you will not know whether it helped. I do it in this order:
- I note the response time of the
get_refreshed_fragmentsrequest from the Network tab on three pages: the home page, a category and the blog. - I run PageSpeed Insights and note the INP result and the server’s first response time. I describe it step by step in the article on how to test your store’s speed.
- In the Query Monitor plugin (only on a copy, or in a short window on the live store) I check how much server time that single AJAX request eats.
Only with those three numbers do I know whether cart fragments are the main problem or just one of several. Sometimes hosting, images or a plugin loading scripts everywhere is what chokes the store, and then disabling cart fragments gives little. The full picture of why a store is slow is in why is my WooCommerce store slow.
How to disable cart fragments outside the cart and checkout
The safest way is to disable them conditionally: where the cart is not needed the script does not load, and on the cart and checkout it keeps working. It takes a short code snippet in your own plugin or a child theme:
add_action( 'wp_enqueue_scripts', function () {
if ( ! is_cart() && ! is_checkout() ) {
wp_dequeue_script( 'wc-cart-fragments' );
}
}, 20 );
Priority 20 is there so the removal runs after WooCommerce adds the script to the queue. I make changes on a copy of the store, with a backup before I start, and I check the result in a fresh logged-out session.
Some stores do it with an optimization plugin that has an option like “disable cart fragments”. That works, but remember the plugin adds its own code and settings, so after turning it on I measure again and check that it did not disable too much.
What can break after disabling
The most common side effect is the header mini-cart. If the theme shows a product count or an amount there, after disabling the script it may stop refreshing after a product is added. The customer adds an item and the counter still shows zero. That is a worse symptom than a slower page, because it looks like a purchase error.
What I check after every change:
- adding a product from the listing page and from the product page, and whether the counter changes;
- behaviour after a reload and after moving to another page;
- the cart and checkout, whether amounts and shipping methods calculate correctly;
- behaviour logged out and on a customer account;
- the phone, because some themes handle the mini-cart differently on a small screen.
If the counter stopped working and the cart matters more than the gain from disabling, there are three ways out: keep the script only on pages that carry the counter, show the counter only after the customer’s first action, or replace it with a lighter solution in your own theme. Which one fits depends on the theme and plugins, so I do not give one recipe for everyone.
What not to do
Do not remove the script across the whole store with one click, because the mini-cart and the side cart then often stop working. Do not trust a single measurement either, because the request can take a very short time once and several times longer the next. And do not test changes on the live store at peak hours.
Also do not assume this is the only cause. In practice cart fragments are one of several elements that add up to a slow store. Disabled, they improve one thing. The rest needs separate fixes.
How I do it in practice
With every store I start with measurement, not with disabling. I check whether the fragments request is a problem at all, on which pages it runs and how long it takes. Only then do I decide whether a conditional disable is enough or whether it is better to change how the counter is shown. After the change I walk the purchase path from adding a product to payment, because the header counter is the easiest place for a hidden bug.
It is one of the things I do as part of development and optimization of stores, and in season I watch it as part of ongoing support for a store. A store that does needless work on every page view rarely fails on an ordinary day. It fails at the peak.
The behaviour of these scripts depends on the WooCommerce version, the theme and the plugins, so always check it on your own store.
Frequently asked questions
Can cart fragments be switched off completely? You can, but usually it is not worth doing across the whole store. The safest way is to disable them only where the cart is not needed and keep them on the cart and checkout. A whole store without this script risks a stale counter.
Do cart fragments slow a store down? Not always. They hurt mainly on a slow server, with heavy scripts and high traffic. On fast hosting with low traffic their effect usually cannot be seen, so measure first.
Does page caching solve it? No. The cache serves the page, but the fragments request still goes to the server, because it is a separate POST request. Good caching helps, yet cart fragments can remain the biggest cost on pages that should be light.
How do I know my store uses cart fragments?
Open the Network tab, reload the page and type get_refreshed_fragments in the filter. If the request appears, the script is running on that page. Check several pages, because the mechanism is sometimes limited to part of the store.
Sitting on this yourself and unsure where to start? I speed up and repair existing sites and stores - Core Web Vitals, outages, the features that are missing. See how I work on it: site and store optimization.