Skip to content

Hooks Reference

Gaurav Tiwari edited this page Aug 27, 2026 · 1 revision

Hooks Reference

Every extension point the plugin fires. All are prefixed gt_performance_.

HTML pipeline

gt_performance_html

apply_filters( 'gt_performance_html', string $html, RequestContext $request ): string

The full response body, immediately before it is stored. This is where every built-in optimizer hooks. Return a non-empty string; anything else is discarded and the original body is used.

$request carries the sanitized method, scheme, host, path, query, cookies, headers and user agent. Every value has already had control characters stripped and lengths bounded.

gt_performance_optimize_stage

Fires around each optimization stage, so you can measure or skip individual stages.

gt_performance_optimized_html

The result after the optimization pipeline has run.

Cache decisions

gt_performance_cache_policy

apply_filters( 'gt_performance_cache_policy', array $policy ): array

The compiled bypass policy — paths, cookies, query parameters — before it is written to the config file and before the Cloudflare expression is compiled from it. Adding a path here protects the origin and the edge in one place.

gt_performance_compiled_config

apply_filters( 'gt_performance_compiled_config', array $config, array $settings ): array

The whole compiled configuration written to config.json.php and read by the drop-in on every request. Last chance to change what the drop-in sees.

gt_performance_cache_stored

do_action( 'gt_performance_cache_stored', RequestContext $request, string $hash )

After an entry is written.

Purging

gt_performance_purged_urls

do_action( 'gt_performance_purged_urls', array $urls, int $count )

gt_performance_purged_all

do_action( 'gt_performance_purged_all', string $scope )

$scope is origin or the edge provider.

gt_performance_enqueue_purge / gt_performance_enqueue_preload

Queue a purge or a preload for a URL from your own code.

gt_performance_revalidate_batch

The batch of stale URLs about to be queued for rebuild.

CSS

gt_performance_css_safelist

add_filter( 'gt_performance_css_safelist', function ( array $selectors ) {
    $selectors[] = '.js-only-modal';
    return $selectors;
} );

Selector fragments that survive pruning unconditionally.

gt_performance_css_stylesheet_exclusions

Stylesheet URL fragments to skip entirely.

JavaScript

gt_performance_javascript_exclusions

add_filter( 'gt_performance_javascript_exclusions', function ( array $fragments ) {
    $fragments[] = '/plugins/my-checkout/';
    return $fragments;
} );

Applies to minify, defer and delay.

Media

gt_performance_media_lazy_load

gt_performance_media_add_dimensions

Per-image control. Return false to leave a specific image alone.

gt_performance_generate_image_variants

gt_performance_rewrite_image_variants

Whether to generate variants for an attachment, and whether to rewrite a given URL to one.

Private Islands

gt_performance_private_fragments

add_filter( 'gt_performance_private_fragments', function ( array $fragments ) {
    $fragments['loyalty_points'] = array(
        'fallback' => '',
        'render'   => fn() => esc_html( my_points_for_current_user() ),
    );
    return $fragments;
} );

The fallback is cached and served to everyone, so it must be safe for everyone. The renderer runs on a public AJAX endpoint.

gt_performance_private_cart_count

gt_performance_private_account_url

Override the built-in fragments without replacing the registry.

Lifecycle

gt_performance_loaded

do_action( 'gt_performance_loaded' )

All modules registered. The right place to add your own filters.

gt_performance_job_{type}

Fires per queue job type, for custom job handling.

gt_performance_core_forms_poll_detected

Emitted by the Core Forms compatibility module.

Scheduled hooks

Hook Schedule
gt_performance_run_queue gtperf_every_minute
gt_performance_database_cleanup daily, gtperf_weekly or gtperf_monthly

Custom schedules registered by the plugin: gtperf_every_minute, gtperf_weekly, gtperf_monthly.

Related

Settings Reference · Private Islands · Architecture

Clone this wiki locally