diff --git a/inc/Engine/Common/PerformanceHints/Frontend/Processor.php b/inc/Engine/Common/PerformanceHints/Frontend/Processor.php index d690fcf518..9a46c3cbcb 100644 --- a/inc/Engine/Common/PerformanceHints/Frontend/Processor.php +++ b/inc/Engine/Common/PerformanceHints/Frontend/Processor.php @@ -95,6 +95,10 @@ public function maybe_apply_optimizations( string $html ): string { * @return string The modified HTML content with the beacon script injected just before the closing body tag. */ private function inject_beacon( $html, $url, $is_mobile ): string { + if ( rocket_get_constant( 'DONOTROCKETOPTIMIZE' ) ) { + return $html; + } + $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; if ( ! $this->filesystem->exists( rocket_get_constant( 'WP_ROCKET_ASSETS_JS_PATH' ) . 'wpr-beacon' . $min . '.js' ) ) { diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php index ba531000f4..bd18707c7d 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php @@ -68,6 +68,19 @@ ], 'expected' => $html_input, ], + 'shouldReturnOriginalWhenDonotoptimize' => [ + 'config' => [ + 'donotrocketoptimize' => true, + 'html' => $html_input, + 'atf' => [ + 'row' => null, + ], + 'lrc' => [ + 'row' => null, + ], + ], + 'expected' => $html_input, + ], 'shouldAddBeaconToPage' => [ 'config' => [ 'html' => $html_input, diff --git a/tests/Integration/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php b/tests/Integration/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php index dda3411799..6b69955ce7 100644 --- a/tests/Integration/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php +++ b/tests/Integration/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php @@ -56,6 +56,7 @@ public function tear_down() { public function testShouldReturnAsExpected( $config, $expected ) { $this->config = $config; $this->cached_user = $config['user_cache_enabled'] ?? false; + $this->donotrocketoptimize = $config['donotrocketoptimize'] ?? null; if ( isset( $config['query_string'] ) ) { $_GET[ $config['query_string'] ] = 1;