Skip to content

Prevent effective asset cache headers audit from running on local/development environments #2035

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

Merged
merged 7 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -22,10 +22,21 @@
* @return array{direct: array<string, array{label: string, test: string}>} Amended tests.
*/
function perflab_effective_asset_cache_headers_add_test( array $tests ): array {
/*
* Static assets are expected to not have effective cache headers in non-production environments.
* Hence bail early.
*
* GH Issue: https://github.com/WordPress/performance/issues/2031
*/
if ( in_array( wp_get_environment_type(), array( 'local', 'development' ), true ) ) {
return $tests;
}

$tests['direct']['effective_asset_cache_headers'] = array(
'label' => __( 'Effective Caching Headers', 'performance-lab' ),
'test' => 'perflab_effective_asset_cache_headers_assets_test',
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is slightly better as it means there is only one return $tests:

Suggested change
if ( in_array( wp_get_environment_type(), array( 'local', 'development' ), true ) ) {
return $tests;
}
$tests['direct']['effective_asset_cache_headers'] = array(
'label' => __( 'Effective Caching Headers', 'performance-lab' ),
'test' => 'perflab_effective_asset_cache_headers_assets_test',
);
if ( ! in_array( wp_get_environment_type(), array( 'local', 'development' ), true ) ) {
$tests['direct']['effective_asset_cache_headers'] = array(
'label' => __( 'Effective Caching Headers', 'performance-lab' ),
'test' => 'perflab_effective_asset_cache_headers_assets_test',
);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, would update this to use only 1 return statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now fixed and function is updated.

Thank You,

return $tests;
}
add_filter( 'site_status_tests', 'perflab_effective_asset_cache_headers_add_test' );
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public function test_perflab_effective_asset_cache_headers_add_test(): void {

$tests = perflab_effective_asset_cache_headers_add_test( $tests );

$this->assertArrayHasKey( 'effective_asset_cache_headers', $tests['direct'] );
$this->assertEquals( 'Effective Caching Headers', $tests['direct']['effective_asset_cache_headers']['label'] );
$this->assertEquals( 'perflab_effective_asset_cache_headers_assets_test', $tests['direct']['effective_asset_cache_headers']['test'] );
$this->assertArrayNotHasKey( 'effective_asset_cache_headers', $tests['direct'] );
}

/**
Expand Down
Loading