WP_Script_Modules::print_script_module_preloads()
Prints the 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.
Return
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.7.2
public function print_script_module_preloads() { foreach ( $this->get_dependencies( array_keys( $this->get_marked_for_enqueue() ), array( 'static' ) ) as $id => $script_module ) { // Don't preload if it's marked for enqueue. if ( true !== $script_module['enqueue'] ) { echo sprintf( '<link rel="modulepreload" href="%s" id="%s">', esc_url( $this->get_src( $id ) ), esc_attr( $id . '-js-modulepreload' ) ); } } }