• Resolved sanderrrrr

    (@sanderrrrr)


    Hello,

    is there a reason this plugin is loaded on every single page?
    Why not load it only on product pages?

    Could you tell me what the CSS and JS handle is?
    See simple example script below.

    function custom_swatches_script_conditional_loading(){
       //  Edit page IDs here
       if(! is_products_page() )    
       {		
          wp_dequeue_style('woo-variation-swatches-tooltip');  // Dequeue CSS file.
       }
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • @sanderrrrr,

    Try the following code

    add_filter( 'disable_wvs_enqueue_scripts', function(){
    // Load only product page. Return true to disable.
    return !! is_product();
    
    } );

    Thank You

    • This reply was modified 4 years, 9 months ago by pluginswoo.
    Thread Starter sanderrrrr

    (@sanderrrrr)

    The code below seemed to fix it. I had to add a priority in order to make this work:

    add_action( 'wp_enqueue_scripts', 'custom_swatches_script_conditional_loading', 99 );
    
    function custom_swatches_script_conditional_loading(){
       //  Edit page IDs here
    if (! is_product()) 
       {		
          wp_dequeue_style('woo-variation-swatches');  // Dequeue CSS file.
    	  wp_dequeue_style('woo-variation-swatches-theme-override');  // Dequeue CSS file.  	
    	  wp_dequeue_style('woo-variation-swatches-tooltip');  // Dequeue CSS file.
    	  wp_dequeue_script('woo-variation-swatches'); // Dequeue JS Script file.
       }
    }

    ===
    Does your suggestion is preferred to the code posted here?

    • This reply was modified 4 years, 9 months ago by sanderrrrr.
    Thread Starter sanderrrrr

    (@sanderrrrr)

    Hello,

    it seems that you are still loading this plugin on every single page, even when there is no products whatsoever. Take for example our homepage which is marked by Google to have an oversize DOM element. Looking at it, this is your plugin. See the code below. Why are you loading this everywhere; and is there a way to make this better? There is really no use in loading this plugin everywhere, just bloating up the code and slowing down the website. Hope you can assist.

    <body class="home page-template-default page page-id-8405 theme-salient woocommerce-js woo-variation-swatches woo-variation-swatches-theme-salient-child woo-variation-swatches-theme-child-salient woo-variation-swatches-style-squared woo-variation-swatches-attribute-behavior-blur woo-variation-swatches-tooltip-enabled woo-variation-swatches-stylesheet-enabled nectar-auto-lightbox original wpb-js-composer js-comp-ver-6.2.0 vc_responsive using-mobile-browser mobile" data-footer-reveal="false" data-footer-reveal-shadow="none" data-header-format="default" data-body-border="off" data-boxed-style="" data-header-breakpoint="1000" data-dropdown-style="minimal" data-cae="linear" data-cad="650" data-megamenu-width="contained" data-aie="none" data-ls="none" data-apte="standard" data-hhun="0" data-fancy-form-rcs="default" data-form-style="default" data-form-submit="default" data-is="minimal" data-button-style="default" data-user-account-button="false" data-flex-cols="true" data-col-gap="default" data-header-inherit-rc="false" data-header-search="true" data-animated-anchors="true" data-ajax-transitions="false" data-full-width-header="true" data-slide-out-widget-area="true" data-slide-out-widget-area-style="slide-out-from-right" data-user-set-ocm="off" data-loading-animation="none" data-bg-header="false" data-responsive="1" data-ext-responsive="true" data-header-resize="0" data-header-color="custom" data-transparent-header="false" data-cart="true" data-remove-m-parallax="1" data-remove-m-video-bgs="" data-m-animate="0" data-force-header-trans-color="light" data-smooth-scrolling="0" data-permanent-transparent="false">

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conditional loading on product pages’ is closed to new replies.