-
Notifications
You must be signed in to change notification settings - Fork 139
Skip stylesheets with empty href attributes in Site Health audit #2281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Skip stylesheets with empty href attributes in Site Health audit #2281
Conversation
Updated the check for the href attribute in perflab_aea_audit_blocking_assets to skip processing when href is an empty string, preventing potential issues with invalid asset URLs.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #2281 +/- ##
=======================================
Coverage 68.86% 68.86%
=======================================
Files 90 90
Lines 7610 7610
=======================================
Hits 5241 5241
Misses 2369 2369
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php
Outdated
Show resolved
Hide resolved
|
Thank you for the PR. Let's also update the unit test to add an assertion for this change. |
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Introduces a test case to verify that styles enqueued with an empty href are handled correctly. This addresses issue WordPress#2278 and ensures that such styles are not included in the audited assets.
Test AddedI've added test coverage for the empty What the test does:
Test assertion:$empty_href_style = array_filter(
$assets['styles'],
static function ( $item ) {
return 'https://empty-href-style.com' === $item['src'];
}
);
$this->assertEmpty( $empty_href_style );This ensures that themes/plugins using performance optimization techniques with href="" won't trigger false positives in Site Health checks. Thanks to @westonruter for the valuable feedback on implementing this test case! Files changed: |
Corrects whitespace in the test for enqueued assets and adds a docblock line for clarity. No functional changes to the test logic.
What:
Skip stylesheet link elements that have empty
hrefattributes during the Enqueued Assets Health Check audit.Why:
Some themes and plugins (like Mesmerize Companion) intentionally use empty
hrefattributes withdata-hrefattributes as a performance optimization technique to defer CSS loading. These stylesheets are non-render-blocking by design, but were being incorrectly flagged as errors ("A valid URL was not provided") in the Site Health Status, negatively impacting site scores.How:
Added a check for empty string
hrefvalues on line 121 inperflab_aea_audit_blocking_assets(). The condition now reads:This skips stylesheets with href="" from being audited, similar to how async CSS with non-standard media attributes is already excluded.
Files changed:
helper.php
Fixes #2278