Fix slow loading on your website due to WooCommerce wc-ajax=get_refreshed_fragments –

Hosting Mautic QuickStart -50% with support in Spanish
24 hours and free training

Send up to 1,000,000 emails/year. Mautic support in Spanish 24 hours, 365 days

WooCommerce is undoubtedly one of the most used plugins to create and manage an online store, currently a large number of E-commerce in WordPress use WooCommerce and consequently one of the functionalities that are used is the call to wc-ajax=get_refreshed_fragments.

These calls affect the performance and speed of our website, delaying the loading between 5 and 10 seconds.

What is wc-ajax=get_refreshed_fragments?

This is an ajax call that is basically made by WooCommerce to try to collect the shopping cart details by calling the script taking a long time to do the task.

WooCommerce calls ” /? wc-ajax = get_refreshed_fragments ” to update the cart items and cart total asynchronously, i.e. without the need to refresh the page of the website you are visiting.

The Script that is displayed on each page of your website can be:

This is how WooCommerce uses the cart fragmentation Ajax call to update the elements and the total that the page has to be updating, but these calls on each page delay the load times of each page in addition to consuming large server resources .

One of the problems is that WooCommerce acts this on each page even if the cart or product details are not found on it, thus slowing down the loading of all the pages of our website, so removing the cart from these pages will not work.

To solve this problem, what we have to do is disable the cart update when there is no cart itself or there are no products in it.

How can we fix the problem with wc-ajax=get_refreshed_fragments

To solve this problem we only have to deactivate this script on the pages that are strictly from the store.

The first thing will be to deactivate the fragmentation of the cart on the front page of our website, for this we have to access our cPanel -> File Manager -> public_html inside this we must place the function.php file (preferably a ) that you will find in wp-content -> themes -> Your_template

/** Disable WooCommerce Ajax calls on front page and entries */ 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’); }

Once we save the changes we have to enter WooCommerce > Settings > Products > General and check the box “Redirect to cart page after successfully adding products” as well as make sure to disable the “Enable AJAX add to cart buttons in files.”

This will allow users to go directly to the cart page without having to wait a long time once a product is added to the cart, otherwise even if a product is added, the details may not be displayed to be on the same page where the fragmentation script was disabled.

Finally we have to disable all the WooCommerce styles and scripts throughout the site, for this we just need to add the following code in the function.php file of our theme

/** Disable all WooCommerce scripts and styles except for shop pages */ 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’ ); } } }

What this code will do is check if we have the WooCommerce plugin active and then disable the scripts and styles on all pages except our product, cart and checkout pages.

Always keep in mind that before making any changes make a backup copy of your original file,

With these options we can thus improve the loading of our page and prevent these scripts from being executed on unnecessary pages.

Help us improve our content by sharing your opinion

WordPress and Woocommerce support team at .

See also  Change the copyright text -
Loading Facebook Comments ...
Loading Disqus Comments ...