Fixed wc-ajax = get_refreshed_fragments High CPU Usage (Disable AJAX Cart Fragments)

A fairly common problem on online stores with WooCommerce is the excessive loading of the processor with the AJAX requests of the shopping cart. Fix wc-ajax = get_refreshed_fragments High CPU Usage.

Excessive loading of processes CPU by any present script, does nothing but to decreases the loading speed of the online store pages, to bring a low SEO and user experience score. Fewer orders on the site.

What is and what is the wc-ajax = get_refreshed_fragments query used for

For everyone's understanding, with the help of this AJAX script, WooCommerce allow adding products to the cart and updating the shopping cart without refreshing the web page. The shopping cart will communicate asynchronously with the host server through AJAX (Asynchronous JavaScript And XML).

Fixed wc-ajax = get_refreshed_fragments High CPU Usage
AJAX Add to Cart

By default, /?wc-ajax=get_refreshed_fragments is present in all the pages of the site to follow the actions Add to Cart of the user and the changes that may appear in the shopping cart widget. These actions are what put processes on CPU and slow down the loading speed of web pages. Sometimes by 4-5 seconds, which is a lot.

Fixed wc-ajax = get_refreshed_fragments High CPU Usage (Disable AJAX Cart Fragments)

If you do not use a dynamic shopping cart widget in the header or in another permanent area of ​​the store, it is best to give up the dynamic update and the tracking of adding/updating cart actions.

You can disable it AJAX Cart Fragments on archive pages and redirect users directly to the shopping cart when a product is added to the cart.

WooCommerce → Settings → Products.

Disable Add to Cart AJAX
Disable Add to Cart AJAX

If you want to leave this script activated "Add to Cart Ajax", but not to run on the first page of the store, edit the functions.php file of the current theme and add the following code:

add_action ('wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11);
function dequeue_woocommerce_cart_fragments () {if (is_front_page ()) wp_dequeue_script ('wc-cart-fragments'); }

In the scenario where besides the pages WooCommerce you also have a blog or other personalized pages on which there are no products, a good idea is to disable the fragments from them.

add_action ('wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11);
function dequeue_woocommerce_cart_fragments () {
if (is_front_page () || is_single ()) wp_dequeue_script ('wc-cart-fragments');
}

Total deactivation and fix wc-ajax = get_refreshed_fragments High CPU Usage (Disable AJAX Cart Fragments) it is done with the following code:

add_action ('wp_enqueue_scripts', 'dequeue_woocommerce_styles_scripts', 99);
function dequeue_woocommerce_styles_scripts () {
if (function_exists ('is_woocommerce')) {
if (! is_woocommerce () &&! is_cart () &&! is_account_page () &&! is_checkout ()) {
# Styles
wp_dequeue_style ('woocommerce-general');
wp_dequeue_style ('woocommerce-layout');
wp_dequeue_style ('woocommerce-smallscreen');
wp_dequeue_style ('woocommerce_frontend_styles');
wp_dequeue_style ('woocommerce_fancybox_styles');
wp_dequeue_style ('woocommerce_chosen_styles');
wp_dequeue_style ('woocommerce_prettyPhoto_css');
# Scripts
wp_dequeue_script ('wc_price_slider');
wp_dequeue_script ('wc-single-product');
wp_dequeue_script ('wc-add-to-cart');
wp_dequeue_script ('wc-cart-fragments');
wp_dequeue_script ('wc-checkout');
wp_dequeue_script ('wc-add-to-cart-variation');
wp_dequeue_script ('wc-single-product');
wp_dequeue_script ('wc-cart');
wp_dequeue_script ('wc-chosen');
wp_dequeue_script ('woocommerce');
wp_dequeue_script ('prettyPhoto');
wp_dequeue_script ('prettyPhoto-init');
wp_dequeue_script ('jquery-blockui');
wp_dequeue_script ('jquery-placeholder');
wp_dequeue_script ('fancybox');
wp_dequeue_script ('jqueryui');
}
}
}

After choosing one of these methods (especially the last one), you will immediately notice an increase in the loading speed of the online store and a much lower consumption of resources on the processor (CPU).

Passionate about technology, I enjoy writing on StealthSettings.com since 2006. I have a rich experience in operating systems: macOS, Windows, and Linux, as well as in programming languages and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, PrestaShop).

How to » WordPress » Fixed wc-ajax = get_refreshed_fragments High CPU Usage (Disable AJAX Cart Fragments)
Leave a Comment