[wp-trac] [WordPress Trac] #44632: Properly enqueue wp-embed
WordPress Trac
noreply at wordpress.org
Mon Oct 11 17:18:13 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 westonruter):
Replying to [comment:9 swissspidy]:
> 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.
I think the reason may be related to #44306, where the `message` event
should be added before iframes load.
To get around this, the script could be printed right before the post
embeds appear on the page. You're right that this is not ideal since it
does block rendering, but better multiple blocking inline scripts than a
one external one?
> 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)
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?
> Just printing in the footer sounds reasonable to me.
If the race condition message passing situation can be figured out, then
great. 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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44632#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list