• Resolved samtulana

    (@samtulana)


    Hello. Explain why it is impossible to make the scripts of the plugin not loaded on pages where it is not needed? After all, this creates additional load on the server.

    Why can not these scripts be removed from pages where it is not used?

    wp-content/plugins/woocommerce/assets/js/jquery-blockui/jquery.blockUI.min.js
    wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js
    wp-content/plugins/woocommerce/assets/js/js-cookie/js.cookie.min.js
    wp-content/plugins/woocommerce/assets/js/frontend/woocommerce.min.js
    wp-content/plugins/woocommerce/assets/js/frontend/cart-fragments.min.js

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • // CSS files
    woocommerce-layout.css
    woocommerce-smallscreen.css
    woocommerce.css

    // JavaScript files
    add-to-cart.min.js
    jquery.blockUI.min.js
    woocommerce.min.js
    jquery.cookie.min.js
    cart-fragments.min.js

    disable all above scripts except cart, checkout, my-account and product page.

    //* Enqueue scripts and styles
    add_action( 'wp_enqueue_scripts', 'disable_woocommerce_loading_css_js' );
     
    function disable_woocommerce_loading_css_js() {
     
    	// Check if WooCommerce plugin is active
    	if( function_exists( 'is_woocommerce' ) ){
     
    		// Check if it's any of WooCommerce page
    		if(! is_woocommerce() && ! is_cart() && ! is_checkout() ) { 		
    			
    			## Dequeue WooCommerce styles
    			wp_dequeue_style('woocommerce-layout'); 
    			wp_dequeue_style('woocommerce-general'); 
    			wp_dequeue_style('woocommerce-smallscreen'); 	
     
    			## Dequeue WooCommerce scripts
    			wp_dequeue_script('wc-cart-fragments');
    			wp_dequeue_script('woocommerce'); 
    			wp_dequeue_script('wc-add-to-cart'); 
    		
    			wp_deregister_script( 'js-cookie' );
    			wp_dequeue_script( 'js-cookie' );
     
    		}
    	}	
    }

    Put above code into your theme’s functions.php file and save your changes.

    Thread Starter samtulana

    (@samtulana)

    Thanks a lot, crslz. The code is working.

    The problem is not even that, but that the plugin developers don’t think about it and don’t immediately bring the solution to the plugin, and the users are suffering from the load on the site, and WordPress has an actual problem.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Scripts are loaded’ is closed to new replies.