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. If a preloaded script module has already been printed, it will not be printed again on subsequent calls to this function.


Source

File: wp-includes/class-wp-script-modules.php

	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 or has already been preloaded.
			if ( true !== $script_module['enqueue'] && false === $script_module['preloaded'] ) {
				// Mark it as preloaded so it doesn't get preloaded again.
				$this->registered[ $id ]['preloaded'] = true;

				echo sprintf(
					'<link rel="modulepreload" href="%s" id="%s">',
					esc_url( $this->get_src( $id ) ),
					esc_attr( $id . '-js-modulepreload' )
				);
			}
		}
	}


Changelog

Changelog
Version Description
6.5.0 Introduced.