Woocommerce & Slow Web Site Speed Test: Fix Cart Fragmentation

A woocmmerce site i had was taking  a long time to load – nearly 20seconds. I was checking  the site on : https://gtmetrix.com and https://developers.google.com/speed/pagespeed/insights/ And i noticed in the Gmetrix response  > In the Waterfall tab there was a Red warning  line that mentioned Cart Fragmentation. It was taking  5 seconds to load and then giving  up. My shop homepage shows products but you cannot buy them from there – the products link to their product pages.** I found this Answer: 3.1. Disable Cart Fragmentation on Front Page https://www.webnots.com/fix-slow-page-loading-with-woocommerce-wc-ajaxget_refreshed_fragments/ and added this code to my child theme function file: /** Disable Ajax Call from WooCommerce for homepage*/ 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’); } I uploaded this and my pagespeed (for desktop) went up to 99%, mobile went up to 55%. ** = if you have add to cart buttons on the page then you have to also: Once the file is updated, navigate to “WooCommerce > Settings” menu and go to the “Display” section under “Products” tab. Enable the checkbox against the option “Redirect to the cart page after successful addition“.

A woocmmerce site i had was taking  a long time to load – nearly 20seconds.

I was checking  the site on :
https://gtmetrix.com
and
https://developers.google.com/speed/pagespeed/insights/

And i noticed in the Gmetrix response  > In the Waterfall tab there was a Red warning  line that mentioned Cart Fragmentation. It was taking  5 seconds to load and then giving  up.

My shop homepage shows products but you cannot buy them from there – the products link to their product pages.**

I found this Answer: 3.1. Disable Cart Fragmentation on Front Page
https://www.webnots.com/fix-slow-page-loading-with-woocommerce-wc-ajaxget_refreshed_fragments/

and added this code to my child theme function file:

/** Disable Ajax Call from WooCommerce for homepage*/
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’); }

I uploaded this and my pagespeed (for desktop) went up to 99%, mobile went up to 55%.

** = if you have add to cart buttons on the page then you have to also:

Once the file is updated, navigate to “WooCommerce > Settings” menu and go to the “Display” section under “Products” tab. Enable the checkbox against the option “Redirect to the cart page after successful addition“.