mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Site Health: Introduce page cache check.
This changeset adds a new `page_cache` check which determines whether the site uses a full page cache, and in addition assesses the server response time. If no page cache is present and the server response time is slow, the check will suggest use of a page cache. A few filters are included for customization of the check: * `site_status_good_response_time_threshold` filters the number of milliseconds below which the server response time is considered good. The default value is based on the `server-response-time` Lighthouse audit and can be altered using this filter. * `site_status_page_cache_supported_cache_headers` filters the map of supported cache headers and their callback to determine whether it was a cache hit. The default list includes commonly used cache headers, and it is filterable to support e.g. additional cache headers used by specific vendors. Note that due to the nature of this check it is only run in production environments. Props furi3r, westonruter, spacedmonkey, swissspidy, Clorith. Fixes #56041. git-svn-id: https://develop.svn.wordpress.org/trunk@54043 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -43,6 +43,7 @@ class WP_REST_Site_Health_Controller extends WP_REST_Controller {
|
||||
* Registers API routes.
|
||||
*
|
||||
* @since 5.6.0
|
||||
* @since 6.1.0 Adds page-cache async test.
|
||||
*
|
||||
* @see register_rest_route()
|
||||
*/
|
||||
@@ -156,6 +157,24 @@ class WP_REST_Site_Health_Controller extends WP_REST_Controller {
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
sprintf(
|
||||
'/%s/%s',
|
||||
$this->rest_base,
|
||||
'page-cache'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array( $this, 'test_page_cache' ),
|
||||
'permission_callback' => function () {
|
||||
return $this->validate_request_permission( 'view_site_health_checks' );
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,6 +261,18 @@ class WP_REST_Site_Health_Controller extends WP_REST_Controller {
|
||||
return $this->site_health->get_test_authorization_header();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that full page cache is active.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @return array The test result.
|
||||
*/
|
||||
public function test_page_cache() {
|
||||
$this->load_admin_textdomain();
|
||||
return $this->site_health->get_test_page_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current directory sizes for this install.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user