Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function perflab_aea_audit_blocking_assets(): array {
}

$href = $processor->get_attribute( 'href' );
if ( ! is_string( $href ) ) {
if ( ! is_string( $href ) || '' === trim( $href ) ) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ public function test_perflab_aea_audit_enqueued_styles(): void {
wp_dequeue_style( 'style3' );
wp_enqueue_style( 'style-print', 'https://print-style.com', array(), null, 'print' );
wp_enqueue_style( 'style-no-href', 'https://no-href-style.com', array(), null );
/**
* Enqueue style with empty href
*
* @see https://github.com/WordPress/performance/issues/2278
*/
wp_enqueue_style( 'style-empty-href', 'https://empty-href-style.com', array(), null );

// Filter to remove href attribute from a specific style handle.
add_filter(
Expand All @@ -176,6 +182,14 @@ static function ( $tag, $handle ) {
if ( 'style-no-href' === $handle ) {
$tag = str_replace( 'href=\'https://no-href-style.com\'', ' ', $tag );
}

if ( 'style-empty-href' === $handle ) {
$tag = str_replace(
'href=\'https://empty-href-style.com\'',
"href=''",
$tag
);
}
return $tag;
},
10,
Expand Down Expand Up @@ -242,6 +256,14 @@ static function ( $item ) {
}
);
$this->assertEmpty( $no_href_style );

$empty_href_style = array_filter(
$assets['styles'],
static function ( $item ) {
return 'https://empty-href-style.com' === $item['src'];
}
);
$this->assertEmpty( $empty_href_style );
}

/**
Expand Down