-
Notifications
You must be signed in to change notification settings - Fork 104
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
Minify script used for ajax activation of features; warn if absent and serve original file when SCRIPT_DEBUG is enabled #1658
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cc3b95f
Add missing JS minification for new PL script
westonruter 1ca7c77
Introduce perflab_get_asset_src()
westonruter f54c488
Change perflab_get_asset_url() to return path instead of URL
westonruter be0401c
Eliminate local env check
westonruter 5509f2c
Update other plugins to warn when minified asset is missing
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
With this added, we should probably add a warning similar to how the other plugins with build processes have? To check in WP Admin that that file actually exists, and otherwise warn about having to run the build.
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 thought about that, but it's unfortunate that the path is hard-coded for each plugin's unique JS file. For Optimization Detective and Web Worker Offloading this build step is critical because the libs for web-vitals and partytown need to be included. Those plugins should be checking specifically for those libs to be present.
For all other cases, however, there is no need for the minified scripts. They could instead just reference the non-minified file instead.
So what about this: if
SCRIPT_DEBUG
is not enabled, we check if the minified script is available, and if not, we force to use the non-minified version and emit awp_trigger_error()
saying that a build is required. A helper function could be copied into each plugin which does 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.
I think that makes sense. Agree we don't need to be as "aggressive" about warning about the build process here, but I think we need to avoid unconditionally calling
wp_scripts_get_suffix()
if we don't know whether the minified version is there.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.
Here's what I have in mind: https://github.com/WordPress/performance/pull/1658/files/cc3b95fdeaab99efeeba964fbee2c5bd589680ce..f54c4884215f6691d934462ca5aedd9820f20d9e
This same function can then be copied into each PL plugin that needs to load a script or stylesheet, and the error will be emitted for each script/stylesheet referenced instead of arbitrarily checking that just one has been built (which would be problematic when additional JS/CSS files are added and then a dev could be confused why it isn't working).
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.
Pretty much, that looks like a good idea. I left comments on that change.