-
Notifications
You must be signed in to change notification settings - Fork 835
Boost: Exclude scripts of type module from concatenation #44193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Boost plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
Full summary · PHP report · JS report Coverage check overridden by
I don't care about code coverage for this PR
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still getting a console error when I have Concat JS enabled with All in One SEO
Though All in One SEO, also came with a few other plugins during my installation, including a google-analytics-for-wordpress
which appears to have caused the error.


From looking at the script, it's actually of type text/javascript
which I assume is plain wrong, though when disabling Concat JS, I do not get an error, so I can confirm Concat JS most likely causes it.
@LiamSarsfield thanks for testing! This was a wild problem to pinpoint. Some plugins hook onto
Unfortunately, their GitHub repo is outdated 😞 so I can't link to up-to-date code... Since Conatenate JS (and page optimize for that matter) don't use I've added a fix to try and mimic what WP core does before outputting a script on the page - https://github.com/WordPress/wordpress-develop/blob/e0ee668d0dc17748be036e0583add30b02f0f2f9/src/wp-includes/class-wp-scripts.php#L411-L441 Unfortunately, it's not perfect, as we don't have access to some data WP has (for example, strategy that's used in the list of attributes can only be retrieved by a private method in We also now properly skip scripts that have an empty URL thanks to this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Console errors are gone now, I have some nitpicks but they're optional
@dilirity Changes look good, but phan is complaining:
|
Fixes HOG-153
Concatenate JS by default doesn't concatenate scripts that are of
type="module"
if they have been correctly enqueued usingwp_enqueue_script_module
. However, some plugins like AIOSEO add thetype="module"
part after the script has been output (by that time, it's been concatenated).This PR fixes that by creating a script tag and checking its type before it's output.
Proposed changes:
type="module
assigned to them after enqueue;script_loader_src
filter, allowing scripts that shouldn't be shown on the page to be shown.Other information:
Jetpack product discussion
HOG-153
Does this pull request change what data or activity we track or use?
no
Testing instructions:
Test that script modules are excluded from concatenation
type="module"
scripts on the page:type="module"
- there should be 2. If you have WP_DEBUG enabled, you should see this:Test that scripts are properly skipped when using filters
google-analytics-for-wordpress
plugin, to be skipped.frontend.min.js
;