WP_Script_Modules::print_script_module_preloads
Prints the static dependencies of the enqueued script modules using link tags with rel="modulepreload" attributes.
If a script module is marked for enqueue, it will not be preloaded.
Method of the class: WP_Script_Modules{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WP_Script_Modules = new WP_Script_Modules(); $WP_Script_Modules->print_script_module_preloads();
Changelog
| Since 6.5.0 | Introduced. |
WP_Script_Modules::print_script_module_preloads() WP Script Modules::print script module preloads code WP 6.9.1
public function print_script_module_preloads() {
$dependency_ids = $this->get_sorted_dependencies( $this->queue, array( 'static' ) );
foreach ( $dependency_ids as $id ) {
// Don't preload if it's marked for enqueue.
if ( in_array( $id, $this->queue, true ) ) {
continue;
}
$src = $this->get_src( $id );
if ( '' === $src ) {
continue;
}
$enqueued_dependents = array_intersect( $this->get_recursive_dependents( $id ), $this->queue );
$highest_fetchpriority = $this->get_highest_fetchpriority( $enqueued_dependents );
printf(
'<link rel="modulepreload" href="%s" id="%s"',
esc_url( $src ),
esc_attr( $id . '-js-modulepreload' )
);
if ( 'auto' !== $highest_fetchpriority ) {
printf( ' fetchpriority="%s"', esc_attr( $highest_fetchpriority ) );
}
if ( $highest_fetchpriority !== $this->registered[ $id ]['fetchpriority'] && 'auto' !== $this->registered[ $id ]['fetchpriority'] ) {
printf( ' data-wp-fetchpriority="%s"', esc_attr( $this->registered[ $id ]['fetchpriority'] ) );
}
echo ">\n";
}
}