[wp-trac] [WordPress Trac] #44632: Properly enqueue wp-embed

WordPress Trac noreply at wordpress.org
Mon Oct 11 17:30:11 UTC 2021


#44632: Properly enqueue wp-embed
-------------------------------------+-------------------------------------
 Reporter:  alpipego                 |       Owner:  westonruter
     Type:  enhancement              |      Status:  accepted
 Priority:  normal                   |   Milestone:  5.9
Component:  Embeds                   |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch has-unit-      |     Focuses:  javascript,
  tests                              |  performance
-------------------------------------+-------------------------------------

Comment (by swissspidy):

 > But `wp_filter_oembed_result` is adding the secret to the initial HTML,
 so it doesn't seem that watching for the `secret` location hash will work
 since it would always be present as I see?

 Ah, right.

 Before I typed that, I actually wanted to propose another idea:

 The host script (`wp-embed.js`) could send a `read` `postMessage` to all
 the embeds on the page once it's loaded. So the individual embeds could
 respond to that by sending the height message in reply.

 So the flow would be:

 1. Host site renders all embeds
 1. All iframes send their `height` message on `load`, just like today
 1. `wp-embed.js` finishes loading, sends `ready` message to all iframes
 1. All iframes send their `height` message in response to the `ready`
 message

 Of course, if the script somehow would be loaded already earlier, the flow
 would be simpler:

 1. Host site renders all embeds
 1. `wp-embed.js` finishes loading, sends `ready` message to all iframes
 1. If an iframe receives the `ready` message but isn't loaded yet, it
 doesn't do anything
 1. All iframes send their `height` message on load, ignoring the `ready`
 which was received

 > But I think this should also conditionally print the script in the
 footer if there was actually any instance of a post embed printed on the
 page.

 Definitely.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44632#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list