Make WordPress Core


Ignore:
Timestamp:
08/31/2022 10:44:04 PM (2 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php

    r50072 r54043  
    4444     *
    4545     * @since 5.6.0
     46     * @since 6.1.0 Adds page-cache async test.
    4647     *
    4748     * @see register_rest_route()
     
    155156                    return $this->validate_request_permission( 'debug_enabled' ) && ! is_multisite();
    156157                },
     158            )
     159        );
     160
     161        register_rest_route(
     162            $this->namespace,
     163            sprintf(
     164                '/%s/%s',
     165                $this->rest_base,
     166                'page-cache'
     167            ),
     168            array(
     169                array(
     170                    'methods'             => 'GET',
     171                    'callback'            => array( $this, 'test_page_cache' ),
     172                    'permission_callback' => function () {
     173                        return $this->validate_request_permission( 'view_site_health_checks' );
     174                    },
     175                ),
    157176            )
    158177        );
     
    241260        $this->load_admin_textdomain();
    242261        return $this->site_health->get_test_authorization_header();
     262    }
     263
     264    /**
     265     * Checks that full page cache is active.
     266     *
     267     * @since 6.1.0
     268     *
     269     * @return array The test result.
     270     */
     271    public function test_page_cache() {
     272        $this->load_admin_textdomain();
     273        return $this->site_health->get_test_page_cache();
    243274    }
    244275
Note: See TracChangeset for help on using the changeset viewer.