Title: Any problems with not optimizing WooCommerce inline Javascript?
Last modified: August 31, 2016

---

# Any problems with not optimizing WooCommerce inline Javascript?

 *  [Marco Almeida | Webdados](https://wordpress.org/support/users/webdados/)
 * (@webdados)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/any-problems-with-not-optimizing-woocommerce-inline-javascript/)
 * Hi there,
 * I’m using [Actionable Google Analytics for WooCommerce](http://codecanyon.net/item/actionable-google-analytics-for-woocommerce/9899552)
   that uses the WooCommerce `wc_enqueue_js` to include specific per page unique
   javscript.
 * This WooCommerce function is using the `wp_footer` action to add inline JS to
   the page.
 * As the javascript is now unique per page, this is making Autoptimize create thousands
   of js files.
 * So i’ve done is this to NOT optimize the WooCommerce inline Javascript at all:
 *     ```
       /* WooCommerce Javascript should not be optimized */
       	remove_action('wp_footer', 'wc_print_js', 25);
       	add_action('wp_footer', function() {
       		echo '<!--noptimize-->';
       	}, 25);
       	add_action('wp_footer', 'wc_print_js', 25);
       	add_action('wp_footer', function() {
       		echo '<!--/noptimize-->';
       	}, 25);
       ```
   
 * has anyone done this before and run into problems?
 * [https://wordpress.org/plugins/autoptimize/](https://wordpress.org/plugins/autoptimize/)

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

 *  Thread Starter [Marco Almeida | Webdados](https://wordpress.org/support/users/webdados/)
 * (@webdados)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/any-problems-with-not-optimizing-woocommerce-inline-javascript/#post-7169747)
 * I’ve contacted the Actionable Google Analytics for WooCommerce plugin authors
   to let them know of this issue:
 * > Your plugin adds the necessary (unique) javascript to each page by using the
   > WooCommerce “wc_enqueue_js” function.
   > We are using Autoptimize [https://wordpress.org/plugins/autoptimize/](https://wordpress.org/plugins/autoptimize/)
   > to minify and combine all the page javascript into a unique JS file, including
   > the inline JavaScript that the WooCommerce function adds to the page.
   >  Autoptimize
   > tests all the javascript that needs to be combined and checks if it has already
   > created a exactly equal combined JS file in the past, and if it has, it just
   > serves that file (which browsers probably already have cached).
   > Because your javascript is unique per page, Autoptimize must create a different
   > JS file for each website unique page. Since we installed your plugin we found
   > out that we had 15k+ files created.
   > To fix this problem, we’ve excluded the WooCommerce inline Javascript from 
   > the optimization problems, but this may lead into other problems that we still
   > cannot anticipate.
   >  See the thread we just started on Autoptimize support forum:
   > [https://wordpress.org/support/topic/any-problems-with-not-optimizing-woocommerce-inline-javascript](https://wordpress.org/support/topic/any-problems-with-not-optimizing-woocommerce-inline-javascript)
   > I would recommend:
   >  – Instead of using the “wc_enqueue_js” function, you should
   > use your own “wp_footer” filter to add your javascript code and enclose it 
   > in <!–nooptimize–> <!–/noptimize–> tags so it will never be processed by Autoptimize–
   > Get in touch with Autoptimize author on that thread and try to find out how
   > to avoid your js code to force the creation of thousand of js files
 *  Thread Starter [Marco Almeida | Webdados](https://wordpress.org/support/users/webdados/)
 * (@webdados)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/any-problems-with-not-optimizing-woocommerce-inline-javascript/#post-7169748)
 * I’ve also submitted an issue on WooCommerce’s GitHub: [https://github.com/woothemes/woocommerce/issues/10553](https://github.com/woothemes/woocommerce/issues/10553)
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/any-problems-with-not-optimizing-woocommerce-inline-javascript/#post-7169754)
 * well, a safer approach would be to only exclude the actionable GA for WC, no?
   either by adding a string that is specific to that block of inline JS in the 
   admin-screen, or by adding the same string to the to-be excluded JS using the
   API (`autoptimize_filter_js_exclude`-filter)?
 * now of course if that “actionable GA for WC” required other JS to be loaded first,
   you might have to either force JS in head or exclude the dependancies as well(
   but you would have noticed that when testing already).
 * frank
 *  Thread Starter [Marco Almeida | Webdados](https://wordpress.org/support/users/webdados/)
 * (@webdados)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/any-problems-with-not-optimizing-woocommerce-inline-javascript/#post-7169765)
 * The problem is that the final block of javascript is a mix from WooCommerce and
   GA for WC, because they’re using the `wc_enqueue_js` function, so it’s not possible(
   I think) to exclude only the GA for WC code.
 * I’m using this at [https://www.vinha.co.uk](https://www.vinha.co.uk) / [https://www.vinha.pt](https://www.vinha.pt)
 *  Thread Starter [Marco Almeida | Webdados](https://wordpress.org/support/users/webdados/)
 * (@webdados)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/any-problems-with-not-optimizing-woocommerce-inline-javascript/#post-7169770)
 * In the meanwhile, WooCommerce 2.6.0 will have a filter on it’s inline Javascript,
   so we can add the nopotimize tags instead for removing and re-adding the action:
   [https://github.com/woothemes/woocommerce/commit/4e1a3d7a0cb295e1d0af782d78d3ca1132d2fa38](https://github.com/woothemes/woocommerce/commit/4e1a3d7a0cb295e1d0af782d78d3ca1132d2fa38)
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/any-problems-with-not-optimizing-woocommerce-inline-javascript/#post-7169777)
 * > The problem is that the final block of javascript is a mix from WooCommerce
   > and GA for WC, because they’re using the wc_enqueue_js function, so it’s not
   > possible (I think) to exclude only the GA for WC code.
 * indeed, wc_enqueue_js spits out one block of JS, so no (easy) way to exclude 
   only GA4WC.

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

The topic ‘Any problems with not optimizing WooCommerce inline Javascript?’ 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/)

 * 6 replies
 * 2 participants
 * Last reply from: [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/any-problems-with-not-optimizing-woocommerce-inline-javascript/#post-7169777)
 * Status: not resolved