Skip to content

Commit 3cba156

Browse files
committed
Emoji: Move printing of emoji loader script module from wp_head to 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
1 parent 3a0f401 commit 3cba156

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

src/js/_enqueues/lib/emoji-loader.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* @output wp-includes/js/wp-emoji-loader.js
33
*/
44

5+
/* eslint-env es6 */
6+
57
// Note: This is loaded as a script module, so there is no need for an IIFE to prevent pollution of the global scope.
68

79
/**
@@ -12,15 +14,13 @@
1214
* @property {?string} source.concatemoji
1315
* @property {?string} source.twemoji
1416
* @property {?string} source.wpemoji
15-
* @property {?boolean} DOMReady
16-
* @property {?Function} readyCallback
1717
*/
1818

1919
const settings = /** @type {WPEmojiSettings} */ (
2020
JSON.parse( document.getElementById( 'wp-emoji-settings' ).textContent )
2121
);
2222

23-
// For compatibility with other scripts that read from this global.
23+
// For compatibility with other scripts that read from this global, in particular wp-includes/js/wp-emoji.js (source file: js/_enqueues/wp/emoji.js).
2424
window._wpemojiSettings = settings;
2525

2626
/**
@@ -422,17 +422,8 @@ new Promise( ( resolve ) => {
422422
settings.supports.everythingExceptFlag &&
423423
! settings.supports.flag;
424424

425-
// Sets DOMReady to false and assigns a ready function to settings.
426-
settings.DOMReady = false;
427-
settings.readyCallback = () => {
428-
settings.DOMReady = true;
429-
};
430-
} )
431-
.then( () => {
432425
// When the browser can not render everything we need to load a polyfill.
433426
if ( ! settings.supports.everything ) {
434-
settings.readyCallback();
435-
436427
const src = settings.source || {};
437428

438429
if ( src.concatemoji ) {

src/js/_enqueues/wp/emoji.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,7 @@
277277
return twemoji.parse( object, params );
278278
}
279279

280-
/**
281-
* Initialize our emoji support, and set up listeners.
282-
*/
283-
if ( settings ) {
284-
if ( settings.DOMReady ) {
285-
load();
286-
} else {
287-
settings.readyCallback = load;
288-
}
289-
}
280+
load();
290281

291282
return {
292283
parse: parse,

src/wp-includes/formatting.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5912,7 +5912,11 @@ function print_emoji_detection_script() {
59125912

59135913
$printed = true;
59145914

5915-
_print_emoji_detection_script();
5915+
if ( did_action( 'wp_print_footer_scripts' ) ) {
5916+
_print_emoji_detection_script();
5917+
} else {
5918+
add_action( 'wp_print_footer_scripts', '_print_emoji_detection_script' );
5919+
}
59165920
}
59175921

59185922
/**

0 commit comments

Comments
 (0)