Opened 2 months ago
Last modified 2 months ago
#62709 new enhancement
Script modules integration with wp_resource_hints
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | minor | Version: | 6.5 |
Component: | Script Loader | Keywords: | |
Focuses: | javascript, performance | Cc: |
Description
The wp_dependencies_unique_hosts() function returns a list of all the unique hosts that appear in script and style dependencies.
That data is used by the wp_resource_hints() function to print DNS <link rel="dns-prefetch" href="{{ HOST_NAME }}">
tags, a performance hint used by browsers.
wp_dependencies_unique_hosts
does not inspect script modules at all. The result is that performance hints are not printed for script modules.
Script modules do handle some of their own performance hints, in particular rel=modulepreload link tags are printed via WP_Script_Modules::print_script_module_preloads(), but script modules miss out on this broader handling of dependencies via wp_resource_hints
for dns-prefetch.
This is likely blocked on #60597, it requires exposing information about script modules for inspection.
Change History (2)
#2
@
2 months ago
- Severity changed from normal to minor
modulepreload
is only added for static module dependencies.
Modules dependencies like the following will not have a modulepreload
added (assuming it's not a static import anywhere else in the dependency graph):
$deps = array(
array( 'id' => 'my-module', 'import' => 'dynamic' ),
);
Dynamic dependencies would still benefit from dns-prefetch.
These dns-prefetches are also added early to the page. On non-block themes, all of the script module tags are printed in the footer so there may also be an opportunity for dns-prefetch to happen before any of the module related tags are processed.
To clarify, you want to add
dns-prefetch
for script modules in addition tomodulepreload
? If you already preload there is no need to prefetch though.