Support » Plugin: WooCommerce PayPal Checkout Payment Gateway » Remove Unused Java Script

  • Resolved troyw2015

    (@troyw2015)


    Hi,
    I have spent the morning reading lots of forums about this and all I am seeing is deep coding solutions, for what shouldn’t be a problem.
    Like 99% of WordPress users, I am not a coder (not a good one anyway).

    Problem is that Google Page Speed Insights is complaining that ‘www.paypal.com’ and ‘paypalobjects’ are killing my website speed.
    It seems that Paypal is loading on all pages of my website, when it should really be loading on just the Woocommerce Pages.

    I have read all about ‘Deregister & Dequeue Stylesheets and Scripts’ and the coding necessary to do this seems ridiculous. Sadly none of the forums that discuss this coding, provide any reasonable examples I can even begin to get my head around.

    I am fairly certain I am not alone with this issue, especially with the Core Web Vitals update looming, so please may I ask.
    Will you be updating your plugin to stop loading on all pages or at least allow users to choose if it does.
    Or, can you provide the appropriate code and where to paste it.

    Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @troyw2015,

    Will you be updating your plugin to stop loading on all pages or at least allow users to choose if it does.

    I’d suggest you create an issue with the exact steps to reproduce in the open source repository and submit it, so the plugin developers can take a look.

    https://github.com/woocommerce/woocommerce-gateway-paypal-express-checkout/issues

    Or, can you provide the appropriate code and where to paste it.

    You can try the code below to disable CSS and JS.

    add_action('wp_enqueue_scripts', 'disable_woocommerce_loading_css_js' );
    
    function disable_woocommerce_loading_css_js() {
    	if(! is_cart() && ! is_checkout() ) { 				
    		wp_dequeue_style('wc-gateway-ppec-frontend'); 
    
    	}
    }

    To add the code:

    1. Install the Code Snippets plugin on your site
    2. You should see a menu item that’s called Snippets in your sidebar
    3. Go to Snippets > Add New
    4. Give your Snippet a name
    5. Copy the code provided above and paste it into your snippet
    6. Save and activate your snippet

    I hope this helps!

    Best

    Thread Starter troyw2015

    (@troyw2015)

    Hi B C. a11n,
    I added that code to my Child Theme, functions.php file and it made no difference at all.
    I will try github, but I tend to find everyone talks in code on there. Like I said, I’m fine to add and edit code, but I can’t create it, which I think is a prerequisite to using Github or Stackoverflow etc.

    Thanks anyway.

    If anyone else see’s this thread and has any ideas, it would be appreciated.

    How about if you adjusted that snippet a bit, e.g.:

    
    add_action('wp_enqueue_scripts', 'disable_woocommerce_loading_css_js', 99 );
    
    function disable_woocommerce_loading_css_js() {
            if(! is_cart() && ! is_checkout() ) {
                    wp_dequeue_style('wc-gateway-ppec-frontend');
                    wp_deregister_script('paypal-checkout-sdk');
            }
    }
    
    Thread Starter troyw2015

    (@troyw2015)

    wbrubaker.a11n,
    Wow, I think that has worked. You are amazing. I’m thinking that this bit of code could fix the biggest problem Page Speed Insights is throwing at us all.
    I will try to apply this other scripts like ZIP Pay and maybe recapcha.

    Please may I ask, where do you find the ‘wc-gateway-ppec-frontend’and ‘paypal-checkout-sdk’?
    Is this in the Plugin editor somewhere?

    Thanks so much.

    • This reply was modified 4 months ago by troyw2015.
    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    Wow, I think that has worked. You are amazing.

    Glad to hear it! I’ll pass this on to @wbrubaker 😄

    Please may I ask, where do you find the ‘wc-gateway-ppec-frontend’and ‘paypal-checkout-sdk’?
    Is this in the Plugin editor somewhere?

    While you could find those by opening up the plugin files in the Plugin Editor and searching through them, probably the easiest way would be to open up the plugin folder in a text editor like Sublime Text. That would allow you to search all files in the plugin at once, and find any places where they are enqueuing/registering styles/scripts.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.