Title: Don&#039;t Include WooCommerce Checkout Scripts
Last modified: August 31, 2016

---

# Don't Include WooCommerce Checkout Scripts

 *  [Patrick Rauland](https://wordpress.org/support/users/bftrick/)
 * (@bftrick)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/)
 * Hello,
 * We’ve had a report from a user where the `Stripe.js` file was optimized with 
   this plugin but it ended up breaking the checkout. Can you please make sure `
   Stripe.js` and files like it aren’t optimized?
 * If you want to test this you can download a free copy of the plugin here: [https://www.woothemes.com/products/stripe/](https://www.woothemes.com/products/stripe/)
 * [https://wordpress.org/plugins/autoptimize/](https://wordpress.org/plugins/autoptimize/)

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

 *  Thread Starter [Patrick Rauland](https://wordpress.org/support/users/bftrick/)
 * (@bftrick)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-7441962)
 * I forgot my manners… please & thank you. 🙂
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-7442061)
 * There’s a filter for that Patrick;
 *     ```
       add_filter('autoptimize_filter_js_exclude','stripe_jsexclude',10,1);
       function stripe_jsexclude($exclude) {
       	return $exclude.", Stripe.js";
       }
       ```
   
 * Just at something similar to your plugin and all will be fine 🙂
 * frank
 *  Thread Starter [Patrick Rauland](https://wordpress.org/support/users/bftrick/)
 * (@bftrick)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-7442108)
 * Hey Frank,
 * There’s close to 100 official payment gateways plus 700+ plugins tagged `payment`
   in the WordPress.org repo. Is there anyway to do this in such a way that we don’t
   have to write 700 pull requests? Is it possible to disable your plugin on the
   checkout page and let the user download all of the scripts individually?
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-7442118)
 * that’s not a pull request, that’s a filter inside your own plugin 🙂
 * now if you want to exclude all JS that comes with your plugin, you can also do
   this (focussing on line 3 of the above code example);
 * `return $exclude.", wp-content/plugins/pluginname/js";`
    or `return $exclude.",
   pluginname/js";` or `return $exclude.", pluginname/payment_gateways/";`
 * lots of possibilities really 🙂
 * disabling AO on the checkout page can be done from within your plugin as well;
 *     ```
       add_filter('autoptimize_filter_noptimize','checkout_noptimize',10,0);
       function checkout_noptimize() {
       	if (strpos($_SERVER['REQUEST_URI'],'/checkout/')!==false) {
       		return true;
       	} else {
       		return false;
       	}
       }
       ```
   
 * Let me know if you need more input!
 * kind regards (& have a nice weekend),
    frank
 *  Thread Starter [Patrick Rauland](https://wordpress.org/support/users/bftrick/)
 * (@bftrick)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-7442119)
 * Hey Frank,
 * I’m trying to say that we would have to update our ~100 gateways and the developers
   for the 700 other plugins on .org would also have to update. It’s problematic
   to make others develop around your plugin.
 * Is there someway to prevent it from working on specific pages? If so, we could
   update your plugin in one place and it could prevent issues on all of the affected
   plugins.
 * Does that make sense?
 * There are some [conditional tags](https://docs.woothemes.com/document/conditional-tags/)
   in WooCommerce which you could use to see if you’re on the checkout page. Ex.
    - `is_cart()`
    - `is_checkout()`
 *  [webaware](https://wordpress.org/support/users/webaware/)
 * (@webaware)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-7442136)
 * [@bftrick](https://wordpress.org/support/users/bftrick/) the WooCommerce checkout
   itself works fine with Autoptimize on it, in several installations I’ve used.
   Personally, as someone who **actually uses** this plugin, I’d prefer to keep 
   it that way.
 * If you need a specific script omitted you can do that by adding it to the Autoptimize
   settings; no code changes required. I wrote this blog post a while ago, but it
   should still be mostly relevant:
 * [https://snippets.webaware.com.au/howto/use-autoptimize-effectively/](https://snippets.webaware.com.au/howto/use-autoptimize-effectively/)
 * You can also, from your plugin, add a `data-noptimize` attribute to your enqueued
   scripts to prevent them being swept up. See this SO topic for a quick how-to:
 * [http://wordpress.stackexchange.com/a/38335/24260](http://wordpress.stackexchange.com/a/38335/24260)
 * Here’s some sample code (PHP5.3+):
 *     ```
       add_filter( 'script_loader_tag', function ( $tag, $handle ) {
   
           if ( 'your-script-handle' !== $handle )
               return $tag;
   
           return str_replace( ' src', ' data-noptimize="1" src', $tag );
       }, 10, 2 );
       ```
   
 * cheers,
    Ross
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-7442141)
 * I (obviously) agree with @webawer on this topic
 * > It’s problematic to make others develop around your plugin.
 * This is the way optimization works I’m afraid; if I would have to try to make
   AO work with all themes and plugins, I would have to cripple it until it’s almost
   useless. The settings-screen has 97% of what people need to fix any issue they
   might encounter (including e.g. excluding stripe.js) and the API covers everything
   else really. The FAQ (and these support forums) are the last piece of the puzzle,
   where a lot of info is available to help people optimize their stuff without 
   breaking anything.
 * frank
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-8148230)
 * [@bftrick](https://wordpress.org/support/users/bftrick/); fyi AO 2.1 (released
   last weekend) comes with new JS defaults (which apply to fresh installs):
    * 
   aggregated JS is not forced in head any more * `js/jquery/jquery.js` is excluded
 * based on [feedback here](https://wordpress.org/support/topic/problems-with-the-addon/#post-8140209)
   for example, these settings fix/ prevent stripe problems.
 * frank
    -  This reply was modified 9 years, 8 months ago by [Frank Goossens](https://wordpress.org/support/users/futtta/).
 *  [webaware](https://wordpress.org/support/users/webaware/)
 * (@webaware)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-8148280)
 * Excluding jQuery is a good idea generally. It’s likely to be included on most
   pages on a website (if at all), so best to let it be loaded once and browser-
   cached separately to any other page-specific scripts. That leads to smaller page-
   specific scripts.
 * My old advice was to use the Use Google Libraries plugin to get jQuery from Google’s
   CDN, but that plugin isn’t kept up to date any more and sites with CloudFlare
   or other origin-pull CDN will work faster with jQuery pulled from the origin 
   site anyway. Your change should be beneficial generally, not just in the circumstances
   described above.
 * cheers,
    Ross
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-8148463)
 * > Your change should be beneficial generally, not just in the circumstances described
   > above.
 * that’s the goal; have AO work on as many sites as possible without users having
   to configure things while limiting the performance sacrifices of those default
   settings (excluding jquery from optimization is a perf. sacrifice, but given 
   the amount of times I had to tell people to do that I consider it worth it).
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-9086653)
 * well [@bftrick](https://wordpress.org/support/users/bftrick/), in a typical case
   of advancing insights; [the upcoming AO 2.2](https://wordpress.org/support/topic/autoptimize-2-2-is-near-need-testers/)
   will now have an option to enable/ disable optimization of cart/ checkout (currently
   for WooCommerce, EDD & WP eCommerce). if you want to test, [the trunk version of AO on wordpress.org](https://downloads.wordpress.org/plugin/autoptimize.zip)
   has those changes already 🙂

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

The topic ‘Don't Include WooCommerce Checkout Scripts’ is closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

## Tags

 * [checkout](https://wordpress.org/support/topic-tag/checkout/)

 * 11 replies
 * 3 participants
 * Last reply from: [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/dont-include-woocommerce-checkout-scripts/#post-9086653)
 * Status: not resolved