Disable WooCommerce Cart Fragments (No Plugins)

disable woocommerce cart fragments

Is your WooCommerce site lagging? One culprit might be AJAX Cart Fragments. When auditing your site’s speed, you might notice numerous slow queries linked to “/?wc-ajax=get_refreshed_fragments”. This guide will help streamline your site efficiently.


Table Of Content


1. Understanding WooCommerce AJAX Cart Fragments

First, let’s simplify AJAX. In web development, AJAX (Asynchronous JavaScript and XML) allows real-time page updates without a full refresh. For instance, when you add items to your WooCommerce cart, the item count updates instantly – thanks to AJAX.

However, AJAX Cart Fragments in WooCommerce, specifically through the URL “yourwebsite.com/?wc-ajax=get_refreshed_fragments”, play a key role. They keep the cart widget updated and respond to any Add to Cart events. While AJAX is vital, it can impact site performance and cause plugin conflicts.


2. Reasons to Disable WooCommerce AJAX Cart Fragments

If your theme doesn’t provide a WooCommerce cart drop-down widget and if you have no products that can be added to a cart on a specific page like your About, Contact, or Homepage, you can remove the entire AJAX functionality.

Even more interestingly, if you choose from your WooCommerce settings to redirect users to the Cart after adding a product to their cart, you’re forcing a page redirect to the Cart page, so the AJAX function is pointless and consuming resources for no reason.

Disabling AJAX Cart Fragments can be beneficial, especially if:

  • Your theme lacks a WooCommerce cart dropdown widget.
  • You’ve set WooCommerce to redirect to the cart page directly after adding a product, rendering AJAX redundant.
  • if you are on a slow hosting provider, it might take up to 2-4 minutes to load and can reduce as well the overall loading speed of your entire website.

3. Step-by-Step Guide to Disable AJAX Cart Fragments

Boost your WooCommerce website’s speed by following these simple 3 steps to disable the cart fragments script: ( Step1 & Step2 are Optional )

Step 1: Adjust WooCommerce Settings

  • Go to WooCommerce Settings.
  • Click on the ‘Products’ tab.

Step 2: Modify Ajax Settings

  • Uncheck the option “Enable Ajax add to cart buttons on archives.”
  • Check “Redirect to the cart page after successful addition.”
optimize woocommerce cart fragment step1
Disable WooCommerce Cart Fragments (No Plugins) 4

These settings help bypass any cache plugins on your site, enhancing performance.


Step 3: Add this code snippet to your Child Theme

The main use of the child theme is to allow customization in the theme files. Any changes you make on the theme files directly will be erased when you update the theme.

That is why we recommend using a child theme when you need to override any theme templates or add code for custom functionality.

Go to ‘Appearance’ > ‘Theme File Editor’. Select your child theme’s functions.php file.

optimize woocommerce cart fragment step2
Disable WooCommerce Cart Fragments (No Plugins) 5
  • Code Purpose: This snippet stops the WooCommerce cart fragments script, speeding up your site.
  • Implementation: Copy and paste the following code at the end of your functions.php file. Remember to save the changes.
/** Disable Ajax Call from WooCommerce */
function sert_dequeue_woocommerce_cart_fragments() { 
    wp_dequeue_script('wc-cart-fragments'); 
}
add_action( 'wp_enqueue_scripts', 
'sert_dequeue_woocommerce_cart_fragments', PHP_INT_MAX);

By dequeuing the JavaScript file, you effectively disable WooCommerce cart fragments, ensuring a faster site even on slower hosting services.


4. Evaluating WooCommerce AJAX Cart Fragments: Pros and Cons

The decision to disable AJAX Cart Fragments in WooCommerce can be a double-edged sword. While it might enhance site speed, it could also disrupt certain functionalities, particularly if you’re using a dropdown cart widget.

Is disabling Cart Fragments truly beneficial for your website’s speed? Does it offer more advantages than drawbacks?

Findings from Industry Experts :

  • Request Time: The “/?wc-ajax=get_refreshed_fragments” request can take up to 448ms, often being the slowest HTTP request.
  • Server Dependency: On slower servers or those with large, unoptimized databases, this request time can exceed 1-2 seconds.
  • Perception vs. Reality: Although this request is non-blocking and occurs post-DOM loading, it impacts fully loaded times and metrics like Time to Interactive and First CPU Idle.

Best Practices for High Traffic Stores

For WooCommerce sites experiencing high traffic and load spikes, a common approach is to:

  1. Dequeue cart fragments.
  2. Remove cart widgets.
  3. Redirect customers to the cart page after adding a product.

5. Making the Right Choice for Your WooCommerce Site

In conclusion, whether to disable WooCommerce AJAX Cart Fragments hinges on your specific site needs and technical setup. Understanding the pros and cons is crucial for making an informed decision that balances speed with functionality.

Boost Your Site’s Performance with Our Hosting Solutions: Don’t let hosting limitations hold back your WooCommerce store. Discover the difference with our dedicated, super-fast WooCommerce hosting solutions. Tailored for optimal performance, which ensures your site runs smoothly, efficiently, and without the common hurdles of standard hosting services.

Further Reading: Don’t miss our essential guide :

, for more expert strategies to enhance your store.


1. What are WooCommerce AJAX Cart Fragments?

WooCommerce AJAX Cart Fragments are a feature that updates the cart content dynamically without needing to reload the entire page. This is particularly useful for showing the latest cart contents in real-time as customers continue shopping.

2. Why might I want to disable AJAX Cart Fragments?

Disabling AJAX Cart Fragments can potentially speed up your WooCommerce site, especially on pages that don’t feature cart-addable products. It can be beneficial for sites with high traffic or on slower hosting servers where these fragments significantly slow down load times.

3. What are the risks of disabling AJAX Cart Fragments?Secure’, and How Can I Fix This?

The main risk is potentially breaking some functionalities of your WooCommerce site, especially if you have a dropdown cart widget. It’s important to understand the technical aspects and test thoroughly before making any changes.

4. How can dedicated WooCommerce hosting solutions benefit my store?

Dedicated WooCommerce hosting solutions are optimized for eCommerce, offering faster load times, enhanced security, and better scalability. This leads to improved user experience, potentially higher conversion rates, and more efficient management of traffic spikes.

5. Can I switch back if I decide to disable AJAX Cart Fragments but change my mind??

Yes, you can revert the changes. If you disable AJAX Cart Fragments and later decide it’s not suitable for your store, you can re-enable it by reversing the steps you took to disable it. However, it’s recommended to backup your site before making such changes for easy restoration.

Similar Posts

Leave a Reply