[wp-trac] [WordPress Trac] #44632: Properly enqueue wp-embed
WordPress Trac
noreply at wordpress.org
Mon Oct 11 13:37:38 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):
Replying to [comment:3 westonruter]:
> Nevertheless, I also just noticed that the `wp-embed` script is printed
on ''every'' page unconditionally. Isn't this incorrect and a negative
impact on page performance? Shouldn't it only ever be printed if there is
an oEmbed on the page which actually outputs an `iframe` with the `wp-
embedded-content` class?
I would have to do some digging to recall ''why'' we originally added the
script in the header. But ''because'' it's printed in the header, it needs
to be done unconditionally, as it's too early to know whether it's
actually going to be needed or not.
Similar to the wp-emoji JS.
> Secondly, this `script` seems it would benefit from the `defer`
attribute being added to it. But the race condition described in #44306
should be figured out. This may entail inlining the `script` before the
first `iframe.wp-embedded-content` instead. So what about doing just that?
What about filtering `embed_oembed_html` to prepend an inlined `wp-embed`
script before post embeds? See [attachment:44632.2.diff].
AFAIK in such a situation the browser will pause parsing the HTML until
the script has been loaded, so that's not ideal.
Just printing in the footer sounds reasonable to me.
To solve the race condition, I think `wp-embed-template.js` should
* not send the message on load if the secret is missing
* send the message as soon as the secret has been added (which means `wp-
embed.js` has been loaded)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44632#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list