WP_Script_Modules::print_script_module_preloads()

In this article

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

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.