Make WordPress Core

Changeset 60902


Ignore:
Timestamp:
10/06/2025 04:49:13 AM (12 months ago)
Author:
westonruter
Message:

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 ​https://github.com/WordPress/wordpress-develop/pull/10145.

Props westonruter, wildworks.
Fixes #63842.
Fixes #64076.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/emoji-loader.js

    r60899 r60902  
    22 * @output wp-includes/js/wp-emoji-loader.js
    33 */
     4
     5/* eslint-env es6 */
    46
    57// Note: This is loaded as a script module, so there is no need for an IIFE to prevent pollution of the global scope.
    … …  
    1315 * @property {?string} source.twemoji
    1416 * @property {?string} source.wpemoji
    15  * @property {?boolean} DOMReady
    16  * @property {?Function} readyCallback
    1717 */
    1818
    … …  
    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).
    2424window._wpemojiSettings = settings;
    2525
    … …  
    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
  • trunk/src/js/_enqueues/wp/emoji.js

    r55186 r60902  
    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 {
  • trunk/src/wp-includes/formatting.php

    r60899 r60902  
    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
Note: See TracChangeset for help on using the changeset viewer.