WP_Scripts::get_eligible_loading_strategy( string $handle ): string

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Gets the best eligible loading strategy for a script.

Parameters

$handlestringrequired
The script handle.

Return

string The best eligible loading strategy.

Source

private function get_eligible_loading_strategy( $handle ) {
	$intended = (string) $this->get_data( $handle, 'strategy' );

	// Bail early if there is no intended strategy.
	if ( ! $intended ) {
		return '';
	}

	/*
	 * If the intended strategy is 'defer', limit the initial list of eligible
	 * strategies, since 'async' can fallback to 'defer', but not vice-versa.
	 */
	$initial = ( 'defer' === $intended ) ? array( 'defer' ) : null;

	$eligible = $this->filter_eligible_strategies( $handle, $initial );

	// Return early once we know the eligible strategy is blocking.
	if ( empty( $eligible ) ) {
		return '';
	}

	return in_array( 'async', $eligible, true ) ? 'async' : 'defer';
}

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.