Speed Up WooCommerce store in few steps

How to optimize a woocommerce site by disabling scripts and store styles

6 Shares
6
0
0

You may have noticed that after installing the WooCommerce module on WordPress, the site starts loading for a long time and lags. And this problem affects not only the store pages, but also the site as a whole, whether it’s a blog or other static pages.

This is due to the fact that the original styles and scripts that relate to WooCommerce are loaded on all pages of the site.

There are several effective methods for optimizing a WooCommerce store:

  • moved products to another table to optimize database queries;
  • Setting up effective caching for store pages;
  • optimization of scripts and styles, as well as other methods of optimizing the site with the WooCommerce module.

Today let’s find out how to disable all styles and scripts so that they are loaded only on the right pages of the online store.

We will talk about other methods of optimizing the store on WordPress in the following articles.

Optimize your WooCommerce store by turning off unused resources

Speed up woocommerce by disabling store resources for WordPress.

To disable loading of unused resources (scripts and styles), simply add the following snippet to the functions.php file or mu-plugin.

add_action(
    'wp_enqueue_scripts',
    function() {
        // If not store page.
        if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
            // Disable styles for non-store pages.
            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' );
             
            // Disable scripts for non-store pages.
            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' ); 
            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' );
        }
    },
    99
);

Note that you can also add your own functions to the snippet.

6 Shares
2 comments
  1. Won’t this snippet for WooCommerce speed optimization negatively affect site performance?

    1. No, it only disables the loading of WooCommerce resources on WordPress pages where those resources are not in use.

Leave a Reply

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