Automattic\WooCommerce\Blocks

AssetsController::add_resource_hints()publicWC 1.0

Defines resource hints to help speed up the loading of some critical blocks.

These will not impact page loading times negatively because they are loaded once the current page is idle.

Метод класса: AssetsController{}

Хуков нет.

Возвращает

Массив. URLs to print for resource hints.

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

$AssetsController = new AssetsController();
$AssetsController->add_resource_hints( $urls, $relation_type );
$urls(массив) (обязательный)
URLs to print for resource hints. Each URL is an array of resource attributes, or a URL string.
$relation_type(строка) (обязательный)
The relation type the URLs are printed. Possible values: preconnect, dns-prefetch, prefetch, prerender.

Код AssetsController::add_resource_hints() WC 8.7.0

public function add_resource_hints( $urls, $relation_type ) {
	if ( ! in_array( $relation_type, array( 'prefetch', 'prerender' ), true ) || is_admin() ) {
		return $urls;
	}

	// We only need to prefetch when the cart has contents.
	$cart = wc()->cart;

	if ( ! $cart instanceof \WC_Cart || 0 === $cart->get_cart_contents_count() ) {
		return $urls;
	}

	if ( 'prefetch' === $relation_type ) {
		$urls = array_merge(
			$urls,
			$this->get_prefetch_resource_hints()
		);
	}

	if ( 'prerender' === $relation_type ) {
		$urls = array_merge(
			$urls,
			$this->get_prerender_resource_hints()
		);
	}

	return $urls;
}