WooCommerce sites, huge ones, almost always encounter load time issues with the following AJAX request.
https://domain.com/?wc-ajax=get_refreshed_fragments
Even on our small WooCommerce test site it took longer than any other request and wasn’t needed as this was on the homepage. On large sites, we have seen this account for up to 10-second delays. That’s right, 10 seconds.
You can disable WooCommerce cart fragments (Ajax) by adding the following code to your theme’s functions.php file:
add_action( 'wp_enqueue_scripts', 'disable_woocommerce_cart_fragments', 11);
function disable_woocommerce_cart_fragments() {
if (is_front_page()) {
wp_dequeue_script('wc-cart-fragments');
}
}
This code disables the WooCommerce cart fragments script only on your site’s front page. If you want to disable it site-wide, you can remove the if (is_front_page())
condition.
You can disable the WooCommerce cart fragments script on specific pages by their IDs by adding the following code to your theme’s functions.php file:
add_action( 'wp_enqueue_scripts', 'disable_woocommerce_cart_fragments', 11);
function disable_woocommerce_cart_fragments() {
// Replace 123 and 456 with the actual page IDs of the pages where you want to disable the cart fragments
$disallowed_page_ids = array( 123, 456 );
if (is_page($disallowed_page_ids)) {
wp_dequeue_script('wc-cart-fragments');
}
}
You can add as many page IDs as you want to the $disallowed_page_ids
array. The script will be disabled on all pages with the specified IDs.