How to Speed up your WooCommerce store

Getting rid of unneeded WooCommerce scripts

If you remember we mentioned earlier that WooCommerce could be developed better.. well one of the things that we hate is that it includes a plethora of scripts and styles on pages that don’t even have WooCommerce. Let’s fix this with some code ūüôā . All you need to do it paste this at the end of your functions.php¬†that’s located inside your theme folder. This will even get you a better score on tools like Pingdom

/**
 * Tweak WooCommerce styles and scripts.
 * credit goes to Greg from: https://gist.github.com/gregrickaby/2846416
 */
function grd_woocommerce_script_cleaner() {
	
	// Remove the generator tag, to reduce WooCommerce based hacking attacks
	remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
	// Unless we're in the store, remove all the scripts and junk!
	if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
		wp_dequeue_style( 'woocommerce_frontend_styles' );
		wp_dequeue_style( 'woocommerce-general');
		wp_dequeue_style( 'woocommerce-layout' );
		wp_dequeue_style( 'woocommerce-smallscreen' );
		wp_dequeue_style( 'woocommerce_fancybox_styles' );
		wp_dequeue_style( 'woocommerce_chosen_styles' );
		wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
		wp_dequeue_style( 'select2' );
		wp_dequeue_script( 'wc-add-payment-method' );
		wp_dequeue_script( 'wc-lost-password' );
		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-credit-card-form' );
		wp_dequeue_script( 'wc-checkout' );
		wp_dequeue_script( 'wc-add-to-cart-variation' );
		wp_dequeue_script( 'wc-single-product' );
		wp_dequeue_script( 'wc-cart' ); // might need to comment out if you have cart icon on all pages
		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( 'jquery-payment' );
		wp_dequeue_script( 'jqueryui' );
		wp_dequeue_script( 'fancybox' );
		wp_dequeue_script( 'wcqi-js' );

	}
}
add_action( 'wp_enqueue_scripts', 'grd_woocommerce_script_cleaner', 99 );

You might want to comment out wp-cart¬†part if you have a theme that uses ajax cart and it’s on every page. Here is a method by the way on how to add cart icon to your top nav.

If you don’t have time to do the above (or don’t know how), use the Selective Plugin method below.

Use selective plugin loading to increase overall speed

We know you should keep the amount of plugins you use on your site to a minimum, however sometimes that’s just not possible.
Use free¬†Plugin Performance Profiler to see which plugin sucks up the speed out of your site (don’t forget to turn it off when done).

Of course the main issue with the plugins is that they love to load their scripts and stylesheets on all your pages. WooCommerce above is a great example. Most of the time however you end up using a plugin only on a single page or maybe only on a specific section of the site. This is where Plugin Organizer comes to the rescue. It may look like 3 year old designed it but it’s an amazing plugin that lets you disable, enable and selectively load plugins based on pages and parts of your site.

plugin-organizer

Once you have it installed go to settings and check each post type and select what plugins you want to be loaded. You can also go to each page and override what you have selected. If you migrate a site make sure you go to settings and click Recreate Permalinks tab and update your url otherwise all your settings will be gone after migration.

That’s about it! Let us know if you think we missed something.