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.

Method of the class: AssetsController{}

No Hooks.

Return

Array. URLs to print for resource hints.

Usage

$AssetsController = new AssetsController();
$AssetsController->add_resource_hints( $urls, $relation_type );
$urls(array) (required)
URLs to print for resource hints. Each URL is an array of resource attributes, or a URL string.
$relation_type(string) (required)
The relation type the URLs are printed. Possible values: preconnect, dns-prefetch, prefetch, prerender.

AssetsController::add_resource_hints() code WC 9.0.1

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;
}