Skip to content

Effective asset cache headers audit should not fail when on local/development environments #2031

Closed
@westonruter

Description

@westonruter

Bug Description

On my local development environment, I'm seeing a Site Health test failure for Performance:

Your site does not serve static assets with an effective caching strategy

This is an false positive because it is intentional that my development environment not have an effective caching strategy for assets, as changes to files should be available whenever I reload the page.

I suggest this test either be omitted when wp_get_environment_type() returns local or development, or that the status be changed from recommended to be left as good on a production or staging environment.

Here's some plugin code that removes the erroneous test on local/development:

add_filter(
	'site_status_tests',
	static function ( array $tests ): array {
		if ( in_array( wp_get_environment_type(), array( 'local', 'development' ), true ) ) {
			// Static assets are expected to not have effective cache headers in non-production/staging environments.
			unset( $tests['direct']['effective_asset_cache_headers'] );
		}
		return $tests;
	},
	100
);

Screenshots

Image

Metadata

Metadata

Assignees

Labels

Good First IssueIssue particularly suitable to be worked on by new contributors[Plugin] Performance LabIssue relates to work in the Performance Lab Plugin only[Type] BugAn existing feature is broken

Type

Projects

Status

Done 😃

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions