Skip to content

Enqueued Assets Site Health test not fully accounting for async CSS #2278

@westonruter

Description

@westonruter

See support topic.

Given a site with the following HTML:

<link rel='stylesheet' id='companion-bundle-css' href="" data-href='http://example.com/style.css' type='text/css' media='all' />

This is showing up as an error:

Image

Note that the audit currently is accounting for async CSS whereby the media is set to something other than screen or all:

} elseif ( 'LINK' === $tag ) {
$rel = $processor->get_attribute( 'rel' );
if ( 'stylesheet' !== strtolower( (string) $rel ) ) {
continue;
}
$media = $processor->get_attribute( 'media' );
if ( is_string( $media ) && 1 !== preg_match( '/^\s*(all|screen)\b/i', $media ) ) {
continue;
}
$href = $processor->get_attribute( 'href' );
if ( ! is_string( $href ) ) {
continue;
}
$size = perflab_aea_get_asset_size( $href );
$result['assets']['styles'][] = array(
'src' => $href,
'size' => is_wp_error( $size ) ? null : $size,
'error' => is_wp_error( $size ) ? $size : null,
);
}

Normally this is accompanied by an onload attribute on the LINK tag to rewrite the media to screen from something like print when the stylesheet has loaded.

We should also account for this case where the href is empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Plugin] Performance LabIssue relates to work in the Performance Lab Plugin only[Type] BugAn existing feature is broken

    Type

    Projects

    Status

    To Do 🔧

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions