[wp-trac] [WordPress Trac] #42438: Add support for preload links (similar to resource hints)
WordPress Trac
noreply at wordpress.org
Thu Aug 18 21:38:33 UTC 2022
#42438: Add support for preload links (similar to resource hints)
-------------------------------------------------+-------------------------
Reporter: nico23 | Owner: swissspidy
Type: enhancement | Status: closed
Priority: normal | Milestone: 6.1
Component: Script Loader | Version: 4.9
Severity: normal | Resolution: fixed
Keywords: has-unit-tests has-patch commit | Focuses:
needs-dev-note | performance
-------------------------------------------------+-------------------------
Comment (by adamsilverstein):
> What are the actual benefits of having a declarative API? I cannot
imagine a scenario where the filter is insufficient to achieve what the
developer wants.
Good question @furi3r! This was proposed by @swissspidy who may want to
weigh in here; in my mind this would be a cleaner way to declare the
preload, especially for a script directly after adding it, adding via a
filter works but is a bit messier.
It doesn't add a new capability, rather a different way of using the
already added capability.
> If the function is added, maybe check if the wp_head action has fired
and log a notice if that is the case.
> Also this will fail if wp_add_preload_resources() is used after
wp_preload_resources(), and the plugin using it will not even know. Worth
mentioning in the docblock at least.
Ah good point, we could fire a "doing_it_wrong" notice if the function is
called after the headers were already output.
> I'm not a fan of globals. It is the (very) old way of doing things and
has many drawbacks
Admittedly, I was following old patterns! How would you suggest building
this? As a class variable? do we have similar code elsewhere in core to
mimic?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42438#comment:70>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list