Checkout-block integration enqueues its script on every request, loading React/w
-
Plugin: SiteGround Email Marketing 1.7.6 (latest). Tested with: WooCommerce 10.9.4 and 11.1.2, WordPress 6.9+.
What happens: When a site has a SiteGround Email Marketing token and the WooCommerce form integration enabled, every front-end page (not just checkout) loads the checkout-block checkbox script and its dependency chain: wc-blocks-checkout, wc-blocks-components, wp-components, React and react-dom, moment, wp-date and the rest of the WooCommerce Blocks stack. On one production news site that is about 40 extra script files and 1.86 MB of decoded JavaScript on every page, 64% of all JS on a category archive.
Cause: core/Integrations/WooCommerce/Woo_Checkout_Block_Integration.php
– initialize() (line 26) calls register_block_frontend_scripts(), which ends with wp_enqueue_script( ‘sg-email-marketing-woo-checkbox-frontend’ ) (line 107).
– WooCommerce calls IntegrationRegistry::initialize() for every checkout-block integration while it constructs its block types (src/Blocks/BlockTypes/AbstractBlock.php:140 in WC 11.1.2), and that happens on every request, not only where a checkout block renders. Loader.php:270 and Woo_Form.php:143 register the integration on woocommerce_blocks_checkout_block_registration.
So the enqueue runs sitewide. initialize() should only register the script. WooCommerce already enqueues the handles returned by get_script_handles() when the Checkout block actually renders.
Fix: delete line 107 (wp_enqueue_script( ‘sg-email-marketing-woo-checkbox-frontend’ );). The wp_register_script and wp_localize_script calls can stay.
Workaround for affected sites:
add_action( ‘wp_print_footer_scripts’, function () {
if ( function_exists( ‘is_checkout’ ) && is_checkout() ) { return; }
wp_dequeue_script( ‘sg-email-marketing-woo-checkbox-frontend’ );
}, 0 );
It has to run at wp_print_footer_scripts priority 0. An earlier dequeue at wp_enqueue_scripts is undone, because the enqueue happens during block registration.
Verified: with the workaround, the checkout still renders the “Sign me up for the newsletter!” checkbox, and non-checkout pages drop the whole chain.
You must be logged in to reply to this topic.