Fix Slow Page Loads caused by WooCommerce

Attempting to Fix Slow Page Loads caused by WooCommerce? You may have noticed  ?wc-ajax=get_refreshed_fragments  in your speed reports. I routinely run into this script tanking my site speeds, and wanted to share a few WooCommerce speed tricks with you.

The Issues

  1. Woocommerce is loading  ?wc-ajax=get_refreshed_framents  on every page.
  2. WooCommerce is attempting to call all of it’s styles and scripts on every page.

The Fixes

Add the below scripts to your theme’s functions.php file.

1. This will disable ?wc-ajax=get_refreshed_framents from loading on every page.

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

2. This will disable All WooCommerce styles and scripts except on shop, product, and other related WooCommerce pages.

/** Disable All WooCommerce  Styles and Scripts on 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_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' );
}
}
}

If your theme utilizes the WooCommerce AJAX shopping cart within menu’s, sidebars, or widgets, you may lose this functionality. You can force users to be redirected after successfully adding a product by adjusting your settings in  WooCommerce -> Settings -> Display -> Products 

Redirect to Cart Page

Other Tips

  • Back-up your functions.php file before making edits.
  • Are you using a cache plugin? Make sure you empty your cache!
  • If the front-end doesn’t load. Something is wrong. 🙂
  • Use pingdom to help find problem scripts, and resources.

Hello, I'm a project manager, previous business owner, web developer, home-owner, parent, and a Cleveland sports fan.

Published by

Corey Schario

Hello, I'm a project manager, previous business owner, web developer, home-owner, parent, and a Cleveland sports fan.

Leave a Reply

Your email address will not be published. Required fields are marked *