WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Admin

Loader::output_header_preload_tags_for_type() public WC 1.0

Output a preload link tag for dependencies (and their sub dependencies) with an optional allowlist.

See: https://macarthur.me/posts/preloading-javascript-in-wordpress

{} It's a method of the class: Loader{}

No Hooks.

Return

null. Nothing.

Usage

$Loader = new Loader();
$Loader->output_header_preload_tags_for_type( $type, $allowlist );
$type(string) (required)
Dependency type - 'script' or 'style'.
$allowlist(array)
List of allowed dependency handles.
Default: array()

Code of Loader::output_header_preload_tags_for_type() WC 5.8.0

public function output_header_preload_tags_for_type( $type, $allowlist = array() ) {
	if ( 'script' === $type ) {
		$dependencies_of_type = wp_scripts();
	} elseif ( 'style' === $type ) {
		$dependencies_of_type = wp_styles();
	} else {
		return;
	}

	foreach ( $dependencies_of_type->queue as $dependency_handle ) {
		$dependency = $dependencies_of_type->query( $dependency_handle, 'registered' );

		if ( false === $dependency ) {
			continue;
		}

		// Preload the subdependencies first.
		foreach ( $dependency->deps as $sub_dependency_handle ) {
			$sub_dependency = $dependencies_of_type->query( $sub_dependency_handle, 'registered' );

			if ( $sub_dependency ) {
				$this->maybe_output_preload_link_tag( $sub_dependency, $type, $allowlist );
			}
		}

		$this->maybe_output_preload_link_tag( $dependency, $type, $allowlist );
	}
}