Combining Javascript files breaks script loading order in Jetpack
-
Hi! We have a compatibility issue with popular Jetpack plugin and Site Optimizer’s “Combine JavaScript files” functionality. Jetpack’s functionality breaks due to how Combine manages script dependencies before combining files.
In Jetpack, there’s a Newsletters subscription block which you can enable by:
- Install Jetpack
- Activate Jetpack, connect your user with WP.com account
- Go to Jetpack -> Settings -> Newsletter and enable “Add subscribe block at the end of each post”. You can also manually add block in block editor.

Now enable “Combine JavaScript Files” from Speed optimizer:

As a logged out user (e.g. in incognito window), see a post with subscription block. Normally when you subscribe, a loading spinner and popup opens (working as expected). With combine javascript active, page just sends you to subscription management site at WP.com (broken experience).
In the source code, functioning site had these scripts in following order:
wp-includes/js/dist/vendor/wp-polyfill.jsconst Jetpack_Block_Assets_Base_Urlwp-includes/js/dist/dom-ready.min.jswp-content/plugins/jetpack/_inc/blocks/subscriptions/view.js?minify=false&ver=13.9-a.5
Non functioning site with “javascript combined” enabled has:
wp-includes/js/dist/vendor/wp-polyfill.min.jswp-content/plugins/jetpack/_inc/blocks/subscriptions/view.js?minify=false&ver=13.9-a.5wp-content/uploads/siteground-optimizer-assets/siteground-optimizer-combined-js-37d52d08d6f7f3b05647602cb89bfa4a.js
The
dom-readyandJetpack_Block_Assets_Base_Urlended up in the combined JS.wp-polyfillisn’t combined because in the plugin it’s whitelisted from being combined.There are at least two bugs here:
- Since
subscriptions/view.jsdepends ondom-readyandJetpack_Block_Assets_Base_Url, Combiner should not break their load order by movingdom-readyinto combined file below theview.js. - Combined should not skip combining the file in first place even if it has
minify=falsein the URL. If I remove theminify=false, combined promptly combines the file normally.
Potential fixes:
- Maintain script loading order at all cost, even if files are skipped from being combined.
- Combine file even if it includes
?minify=falsebit in the URL. - Whitelist
wp-dom-readyfrom being combined like some other core libraries are whitelisted currently; this doesn’t actually fix the root issue, but does solve this specific case. Doesn’t help to optimize the site either so not really in the spirit of the plugin’s purpose.
We have a more technically detailed report of the issue here.
The topic ‘Combining Javascript files breaks script loading order in Jetpack’ is closed to new replies.