Skip to content

Enqueued Assets audit: treat non-cacheable and zero-size responses as errors #2417

@tejas0306

Description

@tejas0306

Summary

The Site Health "Blocking assets" check (Enqueued Assets audit) only treats failed HTTP requests (e.g. non-200 status) as errors. It does not treat non-cacheable responses or zero-byte responses as problems, so the audit can report an asset as OK even when it is bad for performance or effectively broken.

Current behavior

In perflab_aea_get_asset_size(), the code:

  1. Returns WP_Error for wp_remote_get() failures.
  2. Returns WP_Error when the response code is not 200.
  3. Otherwise returns strlen( wp_remote_retrieve_body( $response ) ) as the size.

So if an asset returns 200 with:

  • Cache-Control: no-store (or similar non-cacheable headers), or
  • Body length 0

it is still reported as successful, with no warning or error.

Proposed behavior

  1. Non-cacheable response: If the response indicates the asset should not be cached (e.g. Cache-Control: no-store, no-cache, or missing cache headers where caching would be expected), treat it as an error or warning so the audit can surface it as a performance concern.
  2. Zero-size response: If the response body length is 0, treat it as an error (e.g. return WP_Error or ensure the audit shows a failure) so the check does not report the asset as OK.

Code location

  • File: plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php
  • Function: perflab_aea_get_asset_size() (around lines 497–528)
  • Existing TODOs: Lines 525–526 already note these cases:
    • "A non-cacheable response should also be considered an error."
    • "A size of zero could be considered an error too."

Steps to reproduce (optional)

  1. Install and activate Performance Lab.
  2. Go to Tools → Site Health → Status and run the Blocking assets check.
  3. If any enqueued script or style is served with non-cacheable headers or returns an empty body (e.g. 200 with 0 bytes), the audit currently does not flag it; it would only flag non-200 or request failures.

Acceptance criteria (suggested)

  • Zero-byte response body is treated as an error (audit shows failure for that asset).
  • Non-cacheable response (e.g. Cache-Control: no-store / no-cache or other agreed definition) is treated as an error or warning in the audit.
  • Existing tests pass; new tests cover zero-size and non-cacheable cases where appropriate.

I’d like to work on this after it’s confirmed by the team.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Plugin] Performance LabIssue relates to work in the Performance Lab Plugin only[Type] EnhancementA suggestion for improvement of an existing feature
    No fields configured for Enhancement.

    Projects

    Status

    Not Started/Backlog 📆

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions