should_delay( $handle ); }, null, true ) )->hook( 20 ); add_action( 'wp_footer', [ $self, 'print_loader' ], 99 ); } private function handles() { return (array) apply_filters( 'ablocks/perf/delay_js_handles', [ 'ablocks-blocks-combine-script' ] ); } /** * Whether a script handle should be delayed. Covers the combined per-page * script (assets-generation on) and the per-block frontend scripts * (assets-generation off), so delay works in both modes. * * @param string $handle Script handle. * @return bool */ public function should_delay( $handle ) { if ( in_array( $handle, $this->handles(), true ) ) { return true; } return (bool) preg_match( '/^ablocks-.+-block-static-script$/', (string) $handle ); } /** * Print the tiny vanilla loader that activates delayed scripts on interaction. */ public function print_loader() { $timeout = (int) Helper::get_settings( 'perf_delay_js_timeout', 5000 ); $timeout = max( 0, $timeout ); ?>