Automattic\WooCommerce\Internal\Admin

WCAdminAssets::maybe_output_preload_link_tag()privateWC 1.0

Render a preload link tag for a dependency, optionally checked against a provided allowlist.

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

{} Это метод класса: WCAdminAssets{}

Хуков нет.

Возвращает

null. Ничего.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->maybe_output_preload_link_tag( $dependency, $type, $allowlist );
$dependency(WP_Dependency) (обязательный)
The WP_Dependency being preloaded.
$type(строка) (обязательный)
Dependency type - 'script' or 'style'.
$allowlist(массив)
List of allowed dependency handles.
По умолчанию: array()

Код WCAdminAssets::maybe_output_preload_link_tag() WC 6.6.1

private function maybe_output_preload_link_tag( $dependency, $type, $allowlist = array() ) {
	if (
		(
			! empty( $allowlist ) &&
			! in_array( $dependency->handle, $allowlist, true )
		) ||
		( ! empty( $this->preloaded_dependencies[ $type ] ) &&
		in_array( $dependency->handle, $this->preloaded_dependencies[ $type ], true ) )
	) {
		return;
	}

	$this->preloaded_dependencies[ $type ][] = $dependency->handle;

	$source = $dependency->ver ? add_query_arg( 'ver', $dependency->ver, $dependency->src ) : $dependency->src;

	echo '<link rel="preload" href="', esc_url( $source ), '" as="', esc_attr( $type ), '" />', "\n";
}