If you are seeing woocommerce cart fragments slow down your waterfalls in DevTools or GTmetrix, the culprit is almost always /?wc-ajax=get_refreshed_fragments. This background AJAX request fires on page load to keep the mini-cart accurate on cached pages, but it bypasses your page cache and forces PHP and MySQL to boot WordPress and WooCommerce from scratch. Below is how to diagnose whether it is actually hurting your store and the safest ways to limit or replace it.
Quick answer
wc-ajax=get_refreshed_fragmentsis triggered by thewc-cart-fragmentsscript in classic WooCommerce themes to refresh the mini-cart HTML and item count.- It hurts performance because it cannot be page-cached, consumes PHP workers on every page view, and blocks main-thread rendering if your theme waits on it.
- Do not blindly dequeue
wc-cart-fragmentseverywhere; if your theme has a cached header mini-cart, disabling it will show stale cart counts. - The cleanest fix is to disable cart fragments when the cart is empty, or replace the legacy endpoint with a lightweight Store API or custom REST call.
What wc-ajax=get_refreshed_fragments actually does
When you use full-page caching (Varnish, Nginx FastCGI cache, Cloudflare, or a caching plugin), the HTML served to a visitor is static. If that HTML includes a header mini-cart showing "0 items", a visitor who adds a product to their cart and navigates to another cached page would still see "0 items".
To solve this, WooCommerce enqueues wc-cart-fragments.js on classic themes. On page load, the script checks sessionStorage for cached fragment data. If the data is missing or stale, it fires a POST request to /?wc-ajax=get_refreshed_fragments.
That request hits PHP directly. WordPress loads your active plugins, initializes WooCommerce, reads the customer session from the database, renders the mini-cart template, and returns a JSON object of HTML fragments. On high-traffic stores, this single endpoint often accounts for more PHP worker time than actual page views.
How to diagnose if cart fragments are slowing you down
Before changing any code, confirm that get_refreshed_fragments is genuinely a bottleneck and not just a symptom of slow PHP or an overloaded database.
- Open Chrome DevTools, go to the Network tab, and filter by
wc-ajax. - Reload a cached product or category page in an incognito window (with an empty cart).
- Check the Waterfall and Timing tabs for
get_refreshed_fragments. Look at the Waiting for server response (TTFB) value. - Repeat the test with one item in the cart.
If the TTFB for get_refreshed_fragments is over 300ms, or if you see it firing on every single page load even when the cart is empty, you have a real performance problem. If your server is also running out of PHP-FPM workers during traffic spikes, uncached wc-ajax requests are usually the first place to cut.
Why woocommerce cart fragments slow down classic themes
There are three common reasons this request becomes expensive on production builds:
- Empty-cart requests: By default, a first-time visitor with no cart session still triggers
get_refreshed_fragmentson their first page load ifsessionStorageis empty. - Heavy mini-cart templates: Some themes render full product thumbnails, upsells, or shipping calculators inside
mini-cart.php, which forces extra database queries during the AJAX call. - Plugin hooks on cart calculation: Discount rules, dynamic pricing, and shipping plugins often hook into
woocommerce_add_to_cart_fragmentsorwoocommerce_before_calculate_totals, turning a simple count check into a 800ms+ operation.
Never dequeuewc-cart-fragmentsglobally without testing your header mini-cart on a cached page. If your theme relies on fragments to populate the cart drawer, removing the script will leave returning shoppers staring at an empty cart icon until they visit/cart/.
Fix 1: Disable cart fragments when the cart is empty
On production builds, I start by keeping cart fragments active only when a visitor actually has items in their cart. WooCommerce sets the woocommerce_items_in_cart cookie as soon as a product is added. If that cookie is absent, there is no reason to boot PHP just to confirm the cart is empty.
Add this snippet to your theme's functions.php or a custom must-use plugin:
<?php
add_action( 'wp_enqueue_scripts', function () {
if ( is_admin() || is_cart() || is_checkout() ) {
return;
}
// Only load cart fragments if the visitor has items in their cart.
if ( empty( $_COOKIE['woocommerce_items_in_cart'] ) ) {
wp_dequeue_script( 'wc-cart-fragments' );
}
}, 99 );
This single check eliminates get_refreshed_fragments for 100% of first-time visitors, bots, and browse-only traffic. Once a user clicks "Add to cart", WooCommerce sets the cookie and cart fragments resume normally.
Exclude non-shop pages as well
If your store has a blog, landing pages, or documentation where no mini-cart is displayed, you can go a step further and dequeue wc-cart-fragments on those templates entirely. Just make sure your header does not render a cart icon on those pages, or that the icon links directly to /cart/ without a dynamic counter.
Fix 2: Disable cart fragments everywhere and use the Store API
If you want to eliminate wc-ajax=get_refreshed_fragments completely—even for shoppers with items in their cart—you can dequeue wc-cart-fragments globally and fetch only the cart count and subtotal from the WooCommerce Store API (/wp-json/wc/store/v1/cart).
First, dequeue the legacy script:
<?php
add_action( 'wp_enqueue_scripts', function () {
if ( is_admin() ) {
return;
}
wp_dequeue_script( 'wc-cart-fragments' );
}, 99 );
Then, add a small vanilla JavaScript snippet to update your header cart count on page load when the woocommerce_items_in_cart cookie is present:
document.addEventListener('DOMContentLoaded', async () => {
if (!document.cookie.includes('woocommerce_items_in_cart=1')) {
return;
}
const badge = document.querySelector('.header-cart-count');
if (!badge) return;
try {
const res = await fetch('/wp-json/wc/store/v1/cart', {
credentials: 'same-origin',
});
if (!res.ok) return;
const data = await res.json();
badge.textContent = String(data.items_count ?? 0);
} catch (err) {
// Fail silently so the page remains interactive.
}
});
This approach is faster than get_refreshed_fragments because it skips rendering full HTML templates and avoids jQuery dependencies. Note that if your theme uses a slide-out cart drawer that expects full HTML fragments, you will also need to render the drawer contents from the Store API response or switch to the WooCommerce Mini-Cart block.
Fix 3: Optimize the fragments payload if you must keep it
If you are working on a legacy theme where rewriting the mini-cart drawer is out of scope, you can still cut the cost of get_refreshed_fragments:
- Audit
woocommerce_add_to_cart_fragments: Search your codebase foradd_filter( 'woocommerce_add_to_cart_fragments'and remove any third-party widgets or upsell blocks that do not need to refresh on every page. - Enable persistent object caching: Pairing WooCommerce with Redis reduces the database overhead of reading customer sessions during
wc-ajaxrequests. - Switch to AJAX-free add-to-cart on archives: If your shop archive pages do not need instant drawer updates, disabling AJAX add-to-cart in WooCommerce settings (Products > General) reduces fragment triggers.
Checklist
- Measure
/?wc-ajax=get_refreshed_fragmentsTTFB in Chrome DevTools with an empty cart and with one item in the cart. - Confirm whether your theme's header mini-cart or slide-out drawer depends on
wc-cart-fragments. - Dequeue
wc-cart-fragmentswhenwoocommerce_items_in_cartis empty to protect page caching for browse-only traffic. - Consider replacing
wc-cart-fragmentswith a lightweight/wp-json/wc/store/v1/cartfetch if you only need an item count badge. - Audit
woocommerce_add_to_cart_fragmentsfilters and remove heavy queries from the mini-cart template. - Verify that Redis object caching is active so remaining session reads do not hit MySQL.
Frequently asked questions
Is it safe to disable wc-cart-fragments in WooCommerce?
It is safe to disable wc-cart-fragments when the visitor's cart is empty, or if your theme does not display a dynamic mini-cart in the header. If you disable it globally on a classic theme with a cached header mini-cart, shoppers will see stale cart counts until they visit the cart page.
Why does wc-ajax=get_refreshed_fragments slow down my site?
The wc-ajax=get_refreshed_fragments request cannot be served from a full-page cache. Every time it fires, your server must boot PHP, WordPress, and WooCommerce, load the customer session from the database, and render the mini-cart HTML, which consumes PHP workers and increases server response time.
Does WooCommerce 9 still use cart fragments?
WooCommerce 9 still includes wc-cart-fragments for backward compatibility with classic PHP themes. However, if you use the modern WooCommerce Cart, Checkout, and Mini-Cart blocks, they communicate with the WooCommerce Store API instead of relying on the legacy wc-ajax=get_refreshed_fragments endpoint.
How do I stop get_refreshed_fragments on pages without a cart?
You can dequeue the wc-cart-fragments script on non-shop pages using the wp_enqueue_scripts hook in PHP. Check for pages like blogs or landing pages with conditional tags such as is_front_page() or is_singular('post'), and call wp_dequeue_script('wc-cart-fragments') before the footer renders.
- WooCommerce developer docsWooCommerce developer docs
- WooCommerce documentationWooCommerce documentation
Drafted with AI assistance. Code targets current WordPress, WooCommerce and Next.js APIs; test changes on a staging site before production.