Script Modules API: Move the script modules to the footer in classic themes#5931
Closed
luisherranz wants to merge 2 commits intoWordPress:trunkfrom
Closed
Script Modules API: Move the script modules to the footer in classic themes#5931luisherranz wants to merge 2 commits intoWordPress:trunkfrom
luisherranz wants to merge 2 commits intoWordPress:trunkfrom
Conversation
…ints functionality
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
6 tasks
luisherranz
added a commit
to WordPress/gutenberg
that referenced
this pull request
Jan 23, 2024
Includes this PR WordPress/wordpress-develop#5931
Member
Author
|
FWIW, as I removed the ability to call the print functions more than once because it's now unnecessary, I also removed the |
youknowriad
approved these changes
Jan 24, 2024
Contributor
|
Committed in https://core.trac.wordpress.org/changeset/57345 |
Contributor
Member
Author
|
Thanks, folks! |
cbravobernal
added a commit
to WordPress/gutenberg
that referenced
this pull request
Jan 24, 2024
…ss-6.5 folder (#57778) * Move modules api to 6.5 folder * Update functions to use wp_modules instead of gutenberg_modules * Prevent class redeclaration * Add classic themes conditional * Yet another script position movement * Add gutenberg_*_module deprecations * Add correct version deprecations * Add correct version deprecations * Use correct order for module hooks * Rename module functions to script_module * Rename module functions to script_module * Update files from WP Core Includes this PR WordPress/wordpress-develop#5931 * Fix deprecated version and rename experimental file * Add warning to upcoming deleted file * Refactor file to use only modules * Refactor search block to use only modules * Refactor query block to use only modules * Refactor image block to use only modules * Refactor navigation block to use only modules * Fix some params and add missing DocBlock * Update DEWP readme * Remove tests This code is now tested in WordPress Core. * Update enqueue in new e2e tests * Fix wrong print function names * Remove unnecessary extra argument * Add missing function * Fix redeclared class problem Fixes an issue in PHP 7.0 where we'd see a redeclared class fatal error. * Remove we from docs --------- Co-authored-by: Luis Herranz <luisherranz@gmail.com> Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.




Trac ticket: https://core.trac.wordpress.org/ticket/60240
What
Moves the script module prints to the footer in classic themes. It also removes the ability to call the print functions more than once because it's now unnecessary.
Why
In the ticket that introduced the Script Modules API (#56313), I added a logic that prints as many enqueued and preloads as possible in the head, then prints the remaining ones in the footer and includes the import map. I explain my reasoning in this comment.
But @cbravobernal realized that import maps fail if they appear after the modules. That means that there's no other way but printing the import map first, and then all the modules and preloads (yes, preloads also fail!). So we need to check if we are on a classic or block theme, and if we are in a classic theme, move everything to the footer.
How
By leveraging
wp_is_block_theme()and moving everything to the footer in classic themes:Additional comments
@westonruter mentioned that we could optimize this in the future if we have a way to filter the output before sending the response to the client:
Testing instructions
To check that this fixes the order of the import map:
"bar"was printed in the console.To check that this fixes the positioning of the scripts/link in the classic themes:
type="importmap"andtype="module", and the link withrel="modulepreload"are printed in the head.type="importmap"andtype="module", and the link withrel="modulepreload"are printed in the footer.