Skip to content

WooCommerce cart fragments: the AJAX call that slows every page

Best practices1 min readFixes check woo-cart-fragments

cart-fragments.js can fire an uncacheable request on every page. Disable it outside the cart and checkout.

Step by step, with screenshots: WooCommerce cart fragments: stop the AJAX call on every page →

Check your own site

Runs this check and the other 192, free, in about 45 seconds.

Or run only this check with the free WooCommerce SEO checker.

What it is

WooCommerce cart fragments is a script, cart-fragments.js, that keeps the mini-cart count in your header up to date by calling /?wc-ajax=get_refreshed_fragments from the visitor's browser. That request cannot be served from the page cache, so it reaches PHP and the database every time.

Since WooCommerce 7.8 the script loads only where the Mini-Cart widget or block is used, but many themes and plugins still load it on every page. On a busy shop that is one uncached request per page view, often slower than the cached page itself, and it competes with the content for the visitor's connection.

OK looks like this: the get_refreshed_fragments request runs only on the cart and checkout, or on pages that really show a live cart count. getReport watches the page's network requests and warns when cart fragments run on a non-cart page.

What a passing site looks like

  • No cart-fragments request on this pagewarning · −1.5 ptseffort S

WooCommerce cart fragments

Why it matters. cart-fragments.js fires a wc-ajax=get_refreshed_fragments request to keep the mini-cart count fresh. Since WooCommerce 7.8 it loads only with the Mini-Cart widget or block; here it still loads on a page that is not the cart, often because a theme or plugin enqueues it. The request bypasses the page cache, so every visit costs a PHP request, and it delays the page for a feature most pages do not show.

How to fix it.
  1. Disable cart fragments on pages that are not the cart or checkout. WooCommerce has no setting for it: use the "Disable cart fragments" option in Perfmatters or a similar performance plugin, or a small snippet that dequeues wc-cart-fragments outside the cart, checkout and account pages.
  2. If the header shows a live cart count, load the count from a lightweight endpoint on cart changes only.

Questions people ask

What are WooCommerce cart fragments?

Cart fragments are pieces of HTML, such as the mini-cart and the item count in your header, that WooCommerce refreshes with an AJAX request so they stay correct on cached pages. The request, wc-ajax=get_refreshed_fragments, is sent by cart-fragments.js after the page loads and always bypasses the page cache.

How do you disable WooCommerce cart fragments?

WooCommerce has no setting for it. Use the "Disable cart fragments" option in a performance plugin such as Perfmatters, or a small code snippet that dequeues the wc-cart-fragments script on pages other than the cart, checkout and account pages. Then check that adding to cart still updates the count where you need it.

How do WooCommerce cart fragments work?

After the page loads, cart-fragments.js asks the server for fresh fragments, stores them in the browser's session storage with a cart hash, and swaps them into the page. When the hash changes, for example after an add to cart, it fetches again. The server side runs WooCommerce and your theme's cart templates on every request.

Do cart fragments slow down WooCommerce?

They can. Each request runs PHP and database queries that a page cache would normally skip, often taking several hundred milliseconds under load. On shared hosting with many visitors, these uncached calls can use more server time than all cached page views together.

Filed under WordPress & WooCommerce. Copy is generated from the same catalogue that scores every report, so what you read here is what the report says.