[wp-trac] [WordPress Trac] #58931: Use defer loading strategy for wp-embed script and move to head in block themes

WordPress Trac noreply at wordpress.org
Fri Jul 28 22:53:55 UTC 2023


#58931: Use defer loading strategy for wp-embed script and move to head in block
themes
-------------------------+-------------------------
 Reporter:  westonruter  |      Owner:  westonruter
     Type:  enhancement  |     Status:  assigned
 Priority:  normal       |  Milestone:  6.4
Component:  Embeds       |    Version:  trunk
 Severity:  normal       |   Keywords:
  Focuses:  performance  |
-------------------------+-------------------------
 The `wp-embed` script is printed to the page if there are any post embeds
 present. The script is registered to be printed in the footer. However,
 now that core has support for script loading strategies (#12009), this can
 be revisited. In #58870 the `async` strategy was added to the `comment-
 reply` script while keeping the script in the footer: this is because the
 script is very low priority and only needs to load after the user has
 scrolled down to the comments. For `wp-embed`, however, the situation is
 different. There may very well be post embeds appearing near the top of
 the page. Therefore it is important for `wp-embed` to run as soon as
 possible. This can be achieved by moving the script to the `head` and
 adding the `defer` loading strategy. In this way, the browser will
 discover it early to start loading but wait to execute until the DOM has
 loaded, similar to when it executes today in the footer. This was recently
 done in [https://github.com/WordPress/gutenberg/pull/52536
 gutenberg#52536] where all block view scripts were given the `defer`
 strategy.

 For classic themes the `wp-embed` script and block view scripts would
 continue to be loaded in the footer since the blocks are processed after
 `wp_head` has finished. Block themes on the other hand would be able to
 take advantage of this early-loaded yet deferred `wp-embed` script like
 other block view scripts.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58931>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list