Automattic\WooCommerce\Blocks\Utils

Utils::get_absolute_script_url │ public static │ WC 1.0

Resolve a (possibly relative) script src to an absolute URL the same way WordPress core does in WP_Scripts::do_item(): a relative src is resolved against the scripts base URL (the site URL), unless it already points at the content directory. This keeps the resulting URL consistent with what WordPress itself would emit, including on non-default directory layouts (e.g. a custom WP_CONTENT_DIR/WP_CONTENT_URL).

Method of the class: Utils{}

No Hooks.

Returns

string. The absolute script URL.

Usage

$result = Utils::get_absolute_script_url( $src );
$src(string) (required)
The script src, which may be relative or absolute.

Utils::get_absolute_script_url() code WC 11.3.0

public static function get_absolute_script_url( $src ) {
	$wp_scripts = wc_get_container()->get( LegacyProxy::class )->call_function( 'wp_scripts' );
	if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) {
		$src = $wp_scripts->base_url . $src;
	}
	return $src;
}