W3cubDocs

/WordPress

WP_Script_Modules::print_script_module_preloads()

Prints the the static dependencies of the enqueued script modules using link tags with rel=”modulepreload” attributes.

Description

If a script module is marked for enqueue, it will not be preloaded.

Source

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' )
			);
		}
	}
}

Changelog

Version Description
6.5.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_script_modules/print_script_module_preloads