Skip to content

Commit b7b1441

Browse files
committed
Emoji: Convert the emoji loader from an inline blocking script to a (deferred) script module.
This modernizes the emoji loader script by converting it from a blocking inline script with an IIFE to a script module. Using a script module improves the performance of the FCP and LCP metrics since it does not block the HTML parser. Since script modules are deferred and run immediately before `DOMContentLoaded`, the logic to wait until that event is also now removed. Additionally, since the script is loaded as a module, it has been modernized to use `const`, `let`, and arrow functions. The `sourceURL` comment is also added. See #63887. The emoji settings are now passed via a separate `script` tag with a `type` of `application/json`, following the new "pull" paradigm introduced for exporting data from PHP to script modules. See #58873. The JSON data is also now encoded in a more resilient way according to #63851. When the `wp-emoji-loader.js` script module executes, it continues to populate the `window._wpemojiSettings` global for backwards-compatibility for any extensions that may be using it. A new `uglify:emoji-loader` grunt task is added which ensures `wp-includes/js/wp-emoji-loader.js` is processed as a module and that top-level symbols are minified. Follow-up to [60681]. Props westonruter, jonsurrell, adamsilverstein, peterwilsoncc. See #63851, #63887. Fixes #63842. git-svn-id: https://develop.svn.wordpress.org/trunk@60899 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d6bb737 commit b7b1441

File tree

4 files changed

+459
-414
lines changed

4 files changed

+459
-414
lines changed

Gruntfile.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,17 @@ module.exports = function(grunt) {
838838
'!**/*.min.js',
839839
'!wp-admin/js/custom-header.js', // Why? We should minify this.
840840
'!wp-admin/js/farbtastic.js',
841+
'!wp-includes/js/wp-emoji-loader.js', // This is a module. See the emoji-loader task below.
841842
]
842843
},
844+
'emoji-loader': {
845+
options: {
846+
module: true,
847+
toplevel: true,
848+
},
849+
src: WORKING_DIR + 'wp-includes/js/wp-emoji-loader.js',
850+
dest: WORKING_DIR + 'wp-includes/js/wp-emoji-loader.min.js',
851+
},
843852
'jquery-ui': {
844853
options: {
845854
// Preserve comments that start with a bang.
@@ -1549,6 +1558,7 @@ module.exports = function(grunt) {
15491558

15501559
grunt.registerTask( 'uglify:all', [
15511560
'uglify:core',
1561+
'uglify:emoji-loader',
15521562
'uglify:jquery-ui',
15531563
'uglify:imgareaselect',
15541564
'uglify:jqueryform',

0 commit comments

Comments
 (0)