WooCommerce Cart Fragments Slowing Your Site? How to Find and Fix get_refreshed_fragments

A cached WooCommerce page can still feel slow if every visit fires an uncached get_refreshed_fragments request. This guide shows how to spot it, find what loads it, and limit it without breaking the header cart.

You turn on page caching for a WooCommerce store, and the homepage HTML now arrives in a fraction of a second. Yet the server load barely drops, and the hosting dashboard still shows a steady stream of PHP requests. Open the browser’s Network tab and you will often find the reason: a request to /?wc-ajax=get_refreshed_fragments on page load.

That request comes from WooCommerce’s cart fragments script. It keeps the cart count and mini cart in your header up to date on cached pages. It is useful when someone has items in their cart, but on many stores it runs for visitors who have never added anything, and it can’t be served from the page cache.

What cart fragments do

A page cache stores one copy of each page and serves it to everyone. That breaks anything personal on the page, and the header cart is personal: one visitor has three items, another has none.

The wc-cart-fragments script works around this. After the cached page loads, it asks WooCommerce for the current HTML of the cart parts of the page, called fragments, and swaps them in. It stores the result in the browser’s session storage and reuses it until the cart changes.

The request runs WordPress and WooCommerce in full, with database queries, so it costs roughly as much as an uncached page view. On a busy store, these requests can make up a large share of the server’s PHP work.

Step 1: Confirm the request is there

Open your homepage in a private browser window, so you have no cart and no stored fragments. Open the developer tools, go to the Network tab, type wc-ajax in the filter box and reload.

If you see get_refreshed_fragments, the script is running. Click the request and check its timing. A slow response here, often several hundred milliseconds on shared hosting, is time your server spends on every new visitor.

Then check the page source for cart-fragments to see whether the script is enqueued on pages that have no cart widget at all, such as blog posts or the contact page.

Step 2: Find out what loads it

WooCommerce 7.8 stopped loading the cart fragments script on every page by default. On current versions it is loaded when something asks for it, usually one of these:

  • The classic Cart widget in a sidebar or header widget area
  • A theme with its own header cart, which enqueues the script itself
  • A page builder’s cart or mini cart element
  • An older plugin that adds a floating cart or “added to cart” popup

To find the source, temporarily switch to a default theme on a staging copy and check again. If the request disappears, the theme loads it. If it stays, deactivate cart-related plugins one at a time.

Step 3: Load it only when the visitor has a cart

The cleanest fix for most stores is to keep the script for visitors who have something in their cart, and skip it for everyone else. WooCommerce sets a woocommerce_items_in_cart cookie once a visitor adds a product, so you can check for it:

add_action( 'wp_enqueue_scripts', 'pf_limit_cart_fragments', 99 );

function pf_limit_cart_fragments() {
    if ( ! function_exists( 'is_woocommerce' ) ) {
        return;
    }

    // Keep fragments on shop pages, the cart and checkout.
    if ( is_woocommerce() || is_cart() || is_checkout() ) {
        return;
    }

    // Visitors with items in the cart still get a live header cart.
    if ( ! empty( $_COOKIE['woocommerce_items_in_cart'] ) ) {
        return;
    }

    wp_dequeue_script( 'wc-cart-fragments' );
}

Add it to a small custom plugin or your child theme’s functions.php. The priority of 99 makes it run after the theme and plugins have enqueued their scripts. The wp_dequeue_script() reference explains how dequeuing works.

There is one catch with page caching. If your cache serves the same HTML to visitors with and without the cookie, a visitor with items in the cart could receive a cached page built for someone without one. Most caching plugins and hosts already skip the cache, or keep a separate copy, when the woocommerce_items_in_cart cookie is present. Check your cache settings for a “do not cache when this cookie is set” option, and test by adding a product and browsing to a blog post.

Step 4: Test the header cart

After the change, run through this on a staging copy or in a private window:

  1. Visit a blog post with an empty cart. The get_refreshed_fragments request should be gone.
  2. Add a product to the cart from a product page.
  3. Visit the same blog post again. The header cart should show the right count, and the request should appear again.
  4. Empty the cart and confirm the count goes back to zero.

If the count stays at zero after adding a product, your cache is serving the cookie-less version of the page. Fix the cache exclusion before going further.

Other options

Switching to the WooCommerce Mini-Cart block, on block themes, avoids the classic cart fragments script altogether. The block reads the cart through WooCommerce’s Store API instead.

Several performance plugins have a setting to disable cart fragments. They usually turn the script off everywhere, which breaks a live header cart. Look for an option that keeps it on WooCommerce pages, or use the code above, which keeps it for anyone with items in the cart.

Cleaning up old sessions

WooCommerce stores cart sessions in its own wp_woocommerce_sessions table, and expired sessions are cleared by a scheduled task. If WP-Cron doesn’t run reliably, that table can grow large. While you’re working on store performance, check its size in phpMyAdmin. If the database itself needs attention, WordPress also has a built-in repair and optimize tool.