If your shared cPanel or LiteSpeed box reports a great cache hit ratio and still runs out of PHP workers every afternoon, look at ?wc-ajax=get_refreshed_fragments before you look at anything else. That request comes from wc-cart-fragments.js, which WooCommerce enqueues on every front-end page. It carries a hard cache bypass, so no page cache and no CDN answers it — each one boots WordPress, reads a session row, and builds the mini-cart markup. On a store with a busy crawl budget it is routinely a third of all dynamic hits. You have four real options and only one of them is “turn it off”; the rest of this guide shows how to prove the load, choose between them, and confirm you did not break the add to cart button on the way.
What you’ll accomplish
- Measure exactly what share of your dynamic requests are cart fragments, from the raw access log rather than a plugin dashboard.
- Prove the endpoint is uncacheable at the edge, so you stop chasing cache settings that can never apply to it.
- Choose deliberately between leaving fragments on, dequeuing them conditionally, replacing them with a cookie-driven cart badge, or disabling them outright.
- Ship the change as an mu-plugin that survives theme and plugin updates.
- End with a verified store: mini cart, add to cart, cart page and checkout all exercised after the change, plus a fresh log sample showing the request volume actually dropped.
Prerequisites
WooCommerce 8.x or newer on WordPress 6.4 or newer, PHP 8.1 or later. Shell access as the site user with WP-CLI available as wp, run from the WordPress root. curl on a machine that reaches the site over its public hostname, because half of what you are testing only shows up once the request crosses the cache layer.
Read access to the raw HTTP access log. On cPanel that is usually /home/<user>/logs/<domain>-ssl_log, with /home/<user>/access-logs/ symlinked to the same place on older builds; LiteSpeed Enterprise on cPanel writes to the same files. Adjust every path below to match what ls actually shows you.
Two version caveats. Since WooCommerce 3.x the script caches its result in sessionStorage and compares it against the woocommerce_cart_hash cookie, so a returning visitor inside the same browser session does not re-request. That is why the load looks worse than the pageview count suggests: crawlers, private windows and anything with storage disabled miss that cache on every single hit. And if your storefront is a block theme using the Cart and Checkout blocks, the mini cart is served by the Store API instead and much of this does not apply — check before you start.
How it works
The script is registered as wc-cart-fragments and localised into a JavaScript object named wc_cart_fragments_params, which carries the AJAX URLs and the storage key names. On load it looks for a stored fragment set; if it finds none, or the stored hash disagrees with the woocommerce_cart_hash cookie, it requests /?wc-ajax=get_refreshed_fragments.
That URL is not admin-ajax.php. WooCommerce runs its own front controller: a request carrying a wc-ajax query argument is intercepted early, DONOTCACHEPAGE is defined, and the matching wc_ajax_get_refreshed_fragments action fires. Two things follow from that. First, no page cache will ever serve it, by design — the constant exists precisely to stop that. Second, the same event is registered on admin-ajax.php as woocommerce_get_refreshed_fragments, which is why some themes and older plugins post there instead and why you should grep for both.
The response body is whatever the woocommerce_add_to_cart_fragments filter returns, normally a small JSON object keyed by CSS selectors, plus a cart hash. The payload is tiny. The cost is not the bytes, it is that a full WordPress request happened to produce them.
The relief valve nobody uses is the cookie pair WooCommerce already sets on a non-empty cart: woocommerce_items_in_cart and woocommerce_cart_hash. They exist so a page cache can tell “this visitor has a cart” without reading the session, and they are readable from JavaScript. If all your header needs is a number, the number is already in the browser.
Step-by-step
1. Confirm the script is on your pages at all. Some themes already dequeue it and your problem is elsewhere.
curl -s https://example.com/shop/ | grep -o 'cart-fragments[^"]*'
You should see one or more hits such as cart-fragments.min.js?ver=10.0.4. No output means the script is already gone and the requests you are seeing come from stale cached HTML or from bots replaying an old URL — skip to step 7.
2. Count the fragments share of your traffic. This is the number that justifies the work.
awk '/wc-ajax=get_refreshed_fragments/{f++} {t++} END{printf "total=%d fragments=%d (%.1f%%)\n", t, f, f*100/t}' /home/<user>/logs/example.com-ssl_log
Expect a line like total=418223 fragments=96410 (23.1%). Anything above roughly 10 percent of total requests is worth acting on; above 25 percent it is usually the single biggest source of PHP work on the account.
3. See who is actually sending them. The answer changes which fix is right.
grep 'wc-ajax=get_refreshed_fragments' /home/<user>/logs/example.com-ssl_log | awk -F'"' '{print $6}' | sort | uniq -c | sort -rn | head -15
You are reading the user-agent column of the combined log format. A list dominated by real browser strings means customers are driving it and disabling fragments will be felt. A list topped by crawlers, SEO tools and headless agents means you are spending PHP workers on software that will never buy anything.
4. Measure what one request costs. Compare it against a cached page so the difference is concrete.
curl -s -o /dev/null -w 'fragments http=%{http_code} ttfb=%{time_starttransfer}s bytes=%{size_download}\n' 'https://example.com/?wc-ajax=get_refreshed_fragments'
curl -s -o /dev/null -w 'shop page http=%{http_code} ttfb=%{time_starttransfer}s bytes=%{size_download}\n' 'https://example.com/shop/'
A healthy result looks like fragments http=200 ttfb=0.412s bytes=812 next to shop page http=200 ttfb=0.048s bytes=64110. The fragments call returns almost nothing and still costs eight to ten times the time-to-first-byte of a cached page, because one is PHP and the other is a file read.
5. Prove the endpoint is uncacheable. This stops the “just add it to the cache rules” suggestion before it wastes an afternoon.
curl -sI 'https://example.com/?wc-ajax=get_refreshed_fragments' | grep -iE 'x-litespeed-cache|x-cache|cache-control|content-type'
Expect x-litespeed-cache: miss (or no cache header at all), cache-control: no-cache, must-revalidate, max-age=0 and content-type: application/json. Run it twice: a second miss confirms the bypass is deliberate rather than a cold cache. There is no plugin setting that changes this, because DONOTCACHEPAGE is set by WooCommerce inside the request.
6. Pick your option. The four are genuinely different trades, not a ranking.
Look at your header. If the theme renders a cart icon whose count changes without a page reload, fragments are doing real work. If the header cart is a plain link with no number, or there is no cart link at all, nothing on the page consumes the response.
7. Ship the change as an mu-plugin. Themes get updated and child-theme functions.php edits get lost; an mu-plugin loads before regular plugins and cannot be deactivated by accident.
mkdir -p wp-content/mu-plugins && wp eval 'echo WP_CONTENT_DIR . "/mu-plugins\n";'
The path it prints is where the file goes. Create wp-content/mu-plugins/cart-fragments-policy.php with the header plus exactly one of the blocks below.
<?php
/**
* Plugin Name: Cart fragments policy
* Description: Controls when wc-cart-fragments loads on the front end.
*/
defined( 'ABSPATH' ) || exit;
Option A, leave it in place. No code at all. Correct when the header cart count is part of how customers shop, the account is not resource constrained, and the log from step 3 is dominated by real browsers. Nothing below applies — stop here.
Option B, conditional dequeue. Keep fragments where the cart is being manipulated, drop them everywhere else.
add_action( 'wp_enqueue_scripts', function () {
if ( ! function_exists( 'is_cart' ) ) {
return;
}
if ( is_cart() || is_checkout() || is_account_page() ) {
return;
}
wp_dequeue_script( 'wc-cart-fragments' );
}, 99 );
Priority 99 matters: WooCommerce enqueues at the default priority, so a dequeue at 10 runs too early and does nothing. The condition must depend only on the template, never on cart contents — a check like WC()->cart->is_empty() produces two different HTML outputs for the same URL, and a full-page cache will serve whichever one it stored first to everybody.
Option C, cookie-driven badge. Dequeue as in option B, then paint the count client-side from the cookie WooCommerce already sets. Add a <span class="sh-cart-count"></span> to your header template, rendered empty, and append this:
add_action( 'wp_footer', function () {
echo '<script>(function(){'
. 'var m=document.cookie.match(/(?:^|;\s*)woocommerce_items_in_cart=([^;]*)/);'
. 'var n=m?parseInt(decodeURIComponent(m[1]),10):0;'
. 'document.querySelectorAll(".sh-cart-count").forEach(function(el){'
. 'el.textContent=n>0?String(n):"";el.hidden=(n===0);});'
. '}());</script>';
}, 20 );
Success signal: with an item in the cart, the badge shows the count on a page served from cache, and the network panel shows no wc-ajax request at all. Render the span empty in PHP — if you print the count server-side it gets baked into the cached page and every visitor inherits a stranger’s number.
Option D, disable entirely. Dequeue unconditionally, and stop the endpoint from booting WordPress for clients that still call it.
add_action( 'wp_enqueue_scripts', function () {
wp_dequeue_script( 'wc-cart-fragments' );
}, 99 );
add_action( 'init', function () {
remove_action( 'wp_ajax_woocommerce_get_refreshed_fragments', array( 'WC_AJAX', 'get_refreshed_fragments' ) );
remove_action( 'wp_ajax_nopriv_woocommerce_get_refreshed_fragments', array( 'WC_AJAX', 'get_refreshed_fragments' ) );
}, 99 );
The late init priority is required so the removal runs after WooCommerce has registered the handlers. This still boots WordPress; to stop the request at the web server, add this above the WordPress block in .htaccess, and only once the dequeue is confirmed live:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)wc-ajax=get_refreshed_fragments(&|$)
RewriteRule ^ - [R=204,L]
</IfModule>
After a reload, curl -sI 'https://example.com/?wc-ajax=get_refreshed_fragments' returns HTTP/2 204 with no body and no PHP process involved. Note that WooCommerce re-enqueues the script on cart and checkout regardless of your dequeue in some builds, and that is fine — those pages are already uncached.
Validate it works
First, confirm the script is gone from the pages you targeted and still present where you kept it.
for u in / /shop/ /cart/ /checkout/; do printf '%-12s %s\n' "$u" "$(curl -s "https://example.com$u" | grep -c 'cart-fragments')"; done
Expect zeros on the pages you dequeued and a non-zero count on /cart/ and /checkout/ unless you chose option D. Purge the page cache first, or you are grading old HTML.
Second, exercise the store by hand in a private window: add a simple product from a category archive, watch the header, open the cart page, change a quantity, and reach checkout. The archive matters because that is the AJAX add-to-cart path, and it is the one that depends on fragments in most themes.
Third, take a fresh log sample and compare against step 2.
tail -n 200000 /home/<user>/logs/example.com-ssl_log | awk '/wc-ajax=get_refreshed_fragments/{f++} {t++} END{printf "recent: total=%d fragments=%d (%.1f%%)\n", t, f, f*100/t}'
A share falling from double digits toward one or two percent over the following day is the result you want. It will not hit zero immediately, because cached HTML containing the old script keeps circulating until it expires.
Troubleshooting
The script is still in the page after the dequeue. Three usual causes, in order: the page cache is serving pre-change HTML, so purge and retest; the dequeue ran at priority 10 or earlier and lost the race, so raise it to 99; or the theme registers its own copy of the file under a different handle, which grep -rn "cart-fragments" wp-content/themes/<your-theme>/ will show in seconds.
The add to cart button spins forever now. Some themes bind their success behaviour to the wc_fragments_refreshed event and never get it once the script is gone. That is a real incompatibility, not a bug you can configure away — either move to option B and keep fragments on shop templates, or patch the theme to listen for added_to_cart instead, which wc-add-to-cart.js fires independently.
The cart page quantity update stopped working. You dequeued on cart and checkout too. Those templates use the same script for their own updates; restore the is_cart() and is_checkout() guard.
Requests keep arriving hours after the fix. Look at the user agents again with the step 3 command. Crawlers that indexed the URL will retry it for days, and old cached pages still carry the script. The .htaccess 204 rule ends both, but only apply it if you chose option D — under options B and C the endpoint must keep answering for cart and checkout.
The badge shows a stale number under a page cache. The count is coming from PHP, not from the cookie. Render the span empty and let the JavaScript fill it, and check that no other plugin is printing a count into the same markup.
When this is the wrong approach
If your PHP workers are saturated by something other than fragments — Action Scheduler, a scraper hammering search, a plugin doing remote calls on every page — dequeuing a script will not save you. Measure first; the Action Scheduler backlog guide covers the most common competing culprit, and if the pain shows up as timeouts on the order path rather than site-wide, checkout 504s under load is the closer match.
If the site runs behind Cloudflare with APO, the failure you are more likely chasing is a cart that reads stale rather than a server that is busy, and that has its own APO and WooCommerce cart fix.
If the theme’s entire cart experience is a slide-out drawer that customers actually use, and the store is not resource constrained, disabling fragments trades revenue for a metric. Leave it on and buy capacity instead.
And if you are on a block theme with the Cart and Checkout blocks, or a headless front end, the mini cart talks to the Store API at /wp-json/wc/store/v1/cart and none of the handles above exist on your pages. Different endpoint, different caching story, different guide.
Keep the WooCommerce developer portal open for the AJAX and fragments APIs, and the reference for wp_dequeue_script for the enqueue timing rules that make priority 99 necessary.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.