Skip to content

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

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.

Activity

  1. moved this to Not Started/Backlog 📆 in WP Performance Ongoingon Mar 17, 2026
  2. westonruter commented on Mar 17, 2026

    @westonruter
    Member

    This makes sense to me.

  3. added a commit that references this issue on Mar 17, 2026
    61f27fe
  4. added a commit that references this issue on May 15, 2026
    4bcfe31
  5. moved this from Not Started/Backlog 📆 to Code Review 👀 in WP Performance Ongoingon Jun 18, 2026
  6. moved this from Code Review 👀 to Done 😃 in WP Performance Ongoingon Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions