-
Notifications
You must be signed in to change notification settings - Fork 3.2k
#64076: Emoji loader script can be moved to the footer since non-critical #10145
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
#64076: Emoji loader script can be moved to the footer since non-critical #10145
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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. |
| // Sets DOMReady to false and assigns a ready function to settings. | ||
| settings.DOMReady = false; | ||
| settings.readyCallback = () => { | ||
| settings.DOMReady = true; | ||
| }; |
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.
This code appears to be a vestige of when the emoji was first introduced in 4.2:
wordpress-develop/src/wp-includes/js/wp-emoji-loader.js
Lines 65 to 85 in 7e57307
| settings.DOMReady = false; | |
| settings.readyCallback = function() { | |
| settings.DOMReady = true; | |
| }; | |
| if ( ! settings.supports.simple || ! settings.supports.flag ) { | |
| ready = function() { | |
| settings.readyCallback(); | |
| }; | |
| if ( document.addEventListener ) { | |
| document.addEventListener( 'DOMContentLoaded', ready, false ); | |
| window.addEventListener( 'load', ready, false ); | |
| } else { | |
| window.attachEvent( 'onload', ready ); | |
| document.attachEvent( 'onreadystatechange', function() { | |
| if ( 'complete' === document.readyState ) { | |
| settings.readyCallback(); | |
| } | |
| } ); | |
| } |
The logic was greatly simplified since then, now that DOMContentLoaded is supported by all supported browsers. Also, now that this script is loaded as a module, the DOM will have already been loaded anyway. So it seems like this logic and the corresponding logic in src/js/_enqueues/wp/emoji.js is now unnecessary.
| /** | ||
| * Initialize our emoji support, and set up listeners. | ||
| */ | ||
| if ( settings ) { |
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.
Since this script is loaded by the wp-emoji-loader.js, we know that window._wpemojiSettings will always be defined. Otherwise, if it is not, then the load function would never be executed. So this whole block of code doesn't make sense to me.
…into trac-64076-move-emoji-loader-to-footer
| * Initialize our emoji support, and set up listeners. | ||
| */ | ||
| if ( settings ) { | ||
| if ( settings.DOMReady ) { |
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.
And since wp-emoji-loader.js now runs as a script module, it is deferred to execute at the point that the DOM is constructed, so we know it is ready to go.
t-hamano
left a comment
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.
Thanks for the PR! Everything seems to be working fine.
This is not a blocker, just a question.
- Are we allowed to use the
constformat in core JS exposed to the front-end? My code editor gives me the errorParsing error: The keyword 'const' is reserved. - What if the consumer is loading some script in the head tag and is referencing
window._wpemojiSettingsthere?
Yes, because core blocks use
As part of Core-63842, we did a search for any plugins using this global: #9531 (comment) There just seems to be one relevant: WooPayments. And yet, it doesn't seem to be impacted in my testing, and I concluded with this: #9531 (comment). |
|
I added this module.exports = {
extends: [ 'plugin:@wordpress/eslint-plugin/recommended' ],
};That makes that error with |
|
Ah, I've just added |
|
We can probably ignore the warnings in the code editor for now. |
|
I'll go ahead and commit this now to fix that E2E test in Gutenberg, and we can continue iterating if there is any additional code review feedback. |
…`wp_print_footer_scripts`.
This removes ~3KB of HTML from the critical rendering path of markup in the `head`, thus marginally improving FCP/LCP in slower connections. It also fixes a Firefox issue with script modules by ensuring the emoji loader script module is printed after the `importmap`.
Existing plugins that disable emoji by unhooking the action as follows will continue to work as expected:
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
Additionally, some obsolete `DOMReady` and `readyCallback` logic was removed. A script module (as it has a deferred execution) only ever executes when the DOM is fully loaded. This means there was no need for a `DOMContentLoaded` event which was removed in [60899], and the remaining ready detection logic can be removed.
Follow-up to [60899].
Developed in #10145.
Props westonruter, wildworks.
Fixes #63842.
Fixes #64076.
git-svn-id: https://develop.svn.wordpress.org/trunk@60902 602fd350-edb4-49c9-b593-d223f7449a82
…`wp_print_footer_scripts`.
This removes ~3KB of HTML from the critical rendering path of markup in the `head`, thus marginally improving FCP/LCP in slower connections. It also fixes a Firefox issue with script modules by ensuring the emoji loader script module is printed after the `importmap`.
Existing plugins that disable emoji by unhooking the action as follows will continue to work as expected:
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
Additionally, some obsolete `DOMReady` and `readyCallback` logic was removed. A script module (as it has a deferred execution) only ever executes when the DOM is fully loaded. This means there was no need for a `DOMContentLoaded` event which was removed in [60899], and the remaining ready detection logic can be removed.
Follow-up to [60899].
Developed in WordPress/wordpress-develop#10145.
Props westonruter, wildworks.
Fixes #63842.
Fixes #64076.
Built from https://develop.svn.wordpress.org/trunk@60902
git-svn-id: http://core.svn.wordpress.org/trunk@60238 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…`wp_print_footer_scripts`.
This removes ~3KB of HTML from the critical rendering path of markup in the `head`, thus marginally improving FCP/LCP in slower connections. It also fixes a Firefox issue with script modules by ensuring the emoji loader script module is printed after the `importmap`.
Existing plugins that disable emoji by unhooking the action as follows will continue to work as expected:
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
Additionally, some obsolete `DOMReady` and `readyCallback` logic was removed. A script module (as it has a deferred execution) only ever executes when the DOM is fully loaded. This means there was no need for a `DOMContentLoaded` event which was removed in [60899], and the remaining ready detection logic can be removed.
Follow-up to [60899].
Developed in WordPress/wordpress-develop#10145.
Props westonruter, wildworks.
Fixes #63842.
Fixes #64076.
Built from https://develop.svn.wordpress.org/trunk@60902
git-svn-id: https://core.svn.wordpress.org/trunk@60238 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: https://core.trac.wordpress.org/ticket/64076
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.