From 13088908a36b056fc2b927af620aa4655a576ec6 Mon Sep 17 00:00:00 2001 From: Gael Robin Date: Wed, 10 Apr 2024 14:07:44 +0200 Subject: [PATCH 1/8] Closes #6432: Adds conditions to bail out from beacon --- assets/js/lcp-beacon.js | 27 ++++++- assets/js/lcp-beacon.js.min.map | 2 +- assets/js/lcp-beacon.min.js | 2 +- .../Media/AboveTheFold/AJAX/Controller.php | 30 ++++++++ .../Media/AboveTheFold/AJAX/Subscriber.php | 15 +++- .../AboveTheFold/Frontend/Controller.php | 32 +++++++-- .../AJAX/Subscriber/checkLcpData.php | 70 +++++++++++++++++++ .../AJAX/Subscriber/checkLcpData.php | 53 ++++++++++++++ 8 files changed, 222 insertions(+), 9 deletions(-) create mode 100644 tests/Fixtures/inc/Engine/Media/AboveTheFold/AJAX/Subscriber/checkLcpData.php create mode 100644 tests/Integration/inc/Engine/Media/AboveTheFold/AJAX/Subscriber/checkLcpData.php diff --git a/assets/js/lcp-beacon.js b/assets/js/lcp-beacon.js index 9357a96e35..41830ed0be 100644 --- a/assets/js/lcp-beacon.js +++ b/assets/js/lcp-beacon.js @@ -19,7 +19,7 @@ function LCPCandidates(count) { if (imageURL !== null) { // Insert element into topCandidates in descending order of area for (let i = 0; i < topCandidates.length; i++) { - + if (area > topCandidates[i].area) { topCandidates.splice(i, 0, { element, area, imageURL }); topCandidates.length = Math.min( @@ -68,6 +68,31 @@ function getImageUrlFromElement(element) { let performance_images = []; async function main() { + // AJAX call to check if there are any records for the current URL + const response = await fetch(rocket_lcp_data.ajax_url, { + method: "POST", + credentials: 'same-origin', + body: new URLSearchParams({ + action: 'rocket_check_lcp', + url: rocket_lcp_data.url, + rocket_lcp_nonce: rocket_lcp_data.nonce + }) + }); + const lcp_data = await response.json(); + if ( true === lcp_data.success ) { + console.log('Bailing out because data is already available'); + return; + } + + // Check screen size + const screenWidth = window.innerWidth || document.documentElement.clientWidth; + const screenHeight = window.innerHeight || document.documentElement.clientHeight; + if ( + ( ( screenWidth < rocket_lcp_data.width_threshold || screenHeight < rocket_lcp_data.height_threshold ) ) ) { + console.log('Bailing out because screen size is not acceptable'); + return; + } + // Filter the array based on the condition imageURL is not null const filteredArray = LCPCandidates(1) if (filteredArray.length !== 0) { diff --git a/assets/js/lcp-beacon.js.min.map b/assets/js/lcp-beacon.js.min.map index 5a0b4a3d6b..7b6a7e001a 100644 --- a/assets/js/lcp-beacon.js.min.map +++ b/assets/js/lcp-beacon.js.min.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["lcp-beacon.js"],"sourcesContent":["!function o(r,i,a){function c(t,e){if(!i[t]){if(!r[t]){var n=\"function\"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error(\"Cannot find module '\"+t+\"'\")).code=\"MODULE_NOT_FOUND\",n}n=i[t]={exports:{}},r[t][0].call(n.exports,function(e){return c(r[t][1][e]||e)},n,n.exports,o,r,i,a)}return i[t].exports}for(var l=\"function\"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0i[e].area){i.splice(e,0,{element:t,area:n,imageURL:o}),i.length=Math.min(r,i.length);break}i.length({element:e.element,imageURL:e.imageURL}))}let m=[];async function o(){const e=u(1);0!==e.length?(console.log(\"Estimated LCP element:\",e),m=e.map(e=>({src:e.imageURL,label:\"lcp\"}))):console.log(\"No LCP candidate found.\");for(var t=document.querySelectorAll(\"img\"),n=0;ne.src===o.src)||i!==document||m.push({src:o.src,label:\"above-the-fold\"})}}console.log(m);var l=JSON.stringify(m);window.performance_images_json=l,console.log(l);const d=new FormData;d.append(\"action\",\"rocket_lcp\"),d.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),d.append(\"url\",rocket_lcp_data.url),d.append(\"is_mobile\",rocket_lcp_data.is_mobile),d.append(\"images\",l),d.append(\"status\",\"success\"),await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:d}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}\"loading\"!==document.readyState?(console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")):document.addEventListener(\"DOMContentLoaded\",async function(){console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")})},{}]},{},[1]);"],"file":"lcp-beacon.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["lcp-beacon.js"],"sourcesContent":["!function o(i,c,r){function a(t,e){if(!c[t]){if(!i[t]){var n=\"function\"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error(\"Cannot find module '\"+t+\"'\")).code=\"MODULE_NOT_FOUND\",n}n=c[t]={exports:{}},i[t][0].call(n.exports,function(e){return a(i[t][1][e]||e)},n,n.exports,o,i,c,r)}return c[t].exports}for(var l=\"function\"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0c[e].area){c.splice(e,0,{element:t,area:n,imageURL:o}),c.length=Math.min(i,c.length);break}c.length({element:e.element,imageURL:e.imageURL}))}let g=[];async function o(){const e=await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:new URLSearchParams({action:\"rocket_check_lcp\",url:rocket_lcp_data.url,rocket_lcp_nonce:rocket_lcp_data.nonce})});if(!0!==(await e.json()).success){var t=window.innerWidth||document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;if(t({src:e.imageURL,label:\"lcp\"}))):console.log(\"No LCP candidate found.\");for(var o=document.querySelectorAll(\"img\"),i=0;ie.src===c.src)||a!==document||g.push({src:c.src,label:\"above-the-fold\"})}}console.log(g);n=JSON.stringify(g);window.performance_images_json=n,console.log(n);const u=new FormData;u.append(\"action\",\"rocket_lcp\"),u.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),u.append(\"url\",rocket_lcp_data.url),u.append(\"is_mobile\",rocket_lcp_data.is_mobile),u.append(\"images\",n),u.append(\"status\",\"success\"),await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:u}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log(\"Bailing out because data is already available\")}\"loading\"!==document.readyState?(console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")):document.addEventListener(\"DOMContentLoaded\",async function(){console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")})},{}]},{},[1]);"],"file":"lcp-beacon.js"} \ No newline at end of file diff --git a/assets/js/lcp-beacon.min.js b/assets/js/lcp-beacon.min.js index 58868a3ba2..a1fa186166 100644 --- a/assets/js/lcp-beacon.min.js +++ b/assets/js/lcp-beacon.min.js @@ -1,2 +1,2 @@ -!function o(r,i,a){function c(t,e){if(!i[t]){if(!r[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=i[t]={exports:{}},r[t][0].call(n.exports,function(e){return c(r[t][1][e]||e)},n,n.exports,o,r,i,a)}return i[t].exports}for(var l="function"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0i[e].area){i.splice(e,0,{element:t,area:n,imageURL:o}),i.length=Math.min(r,i.length);break}i.length({element:e.element,imageURL:e.imageURL}))}let m=[];async function o(){const e=u(1);0!==e.length?(console.log("Estimated LCP element:",e),m=e.map(e=>({src:e.imageURL,label:"lcp"}))):console.log("No LCP candidate found.");for(var t=document.querySelectorAll("img"),n=0;ne.src===o.src)||i!==document||m.push({src:o.src,label:"above-the-fold"})}}console.log(m);var l=JSON.stringify(m);window.performance_images_json=l,console.log(l);const d=new FormData;d.append("action","rocket_lcp"),d.append("rocket_lcp_nonce",rocket_lcp_data.nonce),d.append("url",rocket_lcp_data.url),d.append("is_mobile",rocket_lcp_data.is_mobile),d.append("images",l),d.append("status","success"),await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:d}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}"loading"!==document.readyState?(console.time("extract"),setTimeout(o,500),console.timeEnd("extract")):document.addEventListener("DOMContentLoaded",async function(){console.time("extract"),setTimeout(o,500),console.timeEnd("extract")})},{}]},{},[1]); +!function o(i,c,r){function a(t,e){if(!c[t]){if(!i[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=c[t]={exports:{}},i[t][0].call(n.exports,function(e){return a(i[t][1][e]||e)},n,n.exports,o,i,c,r)}return c[t].exports}for(var l="function"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0c[e].area){c.splice(e,0,{element:t,area:n,imageURL:o}),c.length=Math.min(i,c.length);break}c.length({element:e.element,imageURL:e.imageURL}))}let g=[];async function o(){const e=await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:new URLSearchParams({action:"rocket_check_lcp",url:rocket_lcp_data.url,rocket_lcp_nonce:rocket_lcp_data.nonce})});if(!0!==(await e.json()).success){var t=window.innerWidth||document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;if(t({src:e.imageURL,label:"lcp"}))):console.log("No LCP candidate found.");for(var o=document.querySelectorAll("img"),i=0;ie.src===c.src)||a!==document||g.push({src:c.src,label:"above-the-fold"})}}console.log(g);n=JSON.stringify(g);window.performance_images_json=n,console.log(n);const u=new FormData;u.append("action","rocket_lcp"),u.append("rocket_lcp_nonce",rocket_lcp_data.nonce),u.append("url",rocket_lcp_data.url),u.append("is_mobile",rocket_lcp_data.is_mobile),u.append("images",n),u.append("status","success"),await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:u}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log("Bailing out because data is already available")}"loading"!==document.readyState?(console.time("extract"),setTimeout(o,500),console.timeEnd("extract")):document.addEventListener("DOMContentLoaded",async function(){console.time("extract"),setTimeout(o,500),console.timeEnd("extract")})},{}]},{},[1]); //# sourceMappingURL=lcp-beacon.js.map diff --git a/inc/Engine/Media/AboveTheFold/AJAX/Controller.php b/inc/Engine/Media/AboveTheFold/AJAX/Controller.php index 6507efc538..f8d9c1257e 100644 --- a/inc/Engine/Media/AboveTheFold/AJAX/Controller.php +++ b/inc/Engine/Media/AboveTheFold/AJAX/Controller.php @@ -91,4 +91,34 @@ public function add_lcp_data() { wp_send_json_success( $item ); } + + /** + * Checks if there is existing LCP data for the current URL and device type. + * + * This method is called via AJAX. It checks if there is existing LCP data for the current URL and device type. + * If the data exists, it returns a JSON success response with true. If the data does not exist, it returns a JSON success response with false. + * If the context is not allowed, it returns a JSON error response with false. + * + * @return void + */ + public function check_lcp_data() { + check_ajax_referer( 'rocket_lcp', 'rocket_lcp_nonce' ); + + if ( ! $this->context->is_allowed() ) { + wp_send_json_error( false ); + return; + } + + $url = isset( $_POST['url'] ) ? untrailingslashit( esc_url_raw( wp_unslash( $_POST['url'] ) ) ) : ''; + $is_mobile = isset( $_POST['is_mobile'] ) ? filter_var( wp_unslash( $_POST['is_mobile'] ), FILTER_VALIDATE_BOOL ) : false; + + $row = $this->query->get_row( $url, $is_mobile ); + + if ( ! empty( $row ) ) { + wp_send_json_success( 'data already exists' ); + return; + } + + wp_send_json_error( 'data does not exist' ); + } } diff --git a/inc/Engine/Media/AboveTheFold/AJAX/Subscriber.php b/inc/Engine/Media/AboveTheFold/AJAX/Subscriber.php index ba8769aa23..6a070c454b 100644 --- a/inc/Engine/Media/AboveTheFold/AJAX/Subscriber.php +++ b/inc/Engine/Media/AboveTheFold/AJAX/Subscriber.php @@ -29,8 +29,10 @@ public function __construct( Controller $controller ) { */ public static function get_subscribed_events() { return [ - 'wp_ajax_rocket_lcp' => 'add_lcp_data', - 'wp_ajax_nopriv_rocket_lcp' => 'add_lcp_data', + 'wp_ajax_rocket_lcp' => 'add_lcp_data', + 'wp_ajax_nopriv_rocket_lcp' => 'add_lcp_data', + 'wp_ajax_rocket_check_lcp' => 'check_lcp_data', + 'wp_ajax_nopriv_rocket_check_lcp' => 'check_lcp_data', ]; } @@ -42,4 +44,13 @@ public static function get_subscribed_events() { public function add_lcp_data() { $this->controller->add_lcp_data(); } + + /** + * Callback for checking lcp data + * + * @return void + */ + public function check_lcp_data() { + $this->controller->check_lcp_data(); + } } diff --git a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php index 88303e955b..bc40a904b8 100644 --- a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php +++ b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php @@ -350,11 +350,35 @@ public function inject_beacon( $html, $url, $is_mobile ): string { return $html; } + /** + * Filters the width threshold for the LCP beacon. + * + * @param int $width_threshold The width threshold. Default is 393 for mobile and 1920 for others. + * @param bool $is_mobile True if the current device is mobile, false otherwise. + * @param string $url The current URL. + * + * @return int The filtered width threshold. + */ + $width_threshold = apply_filters( 'rocket_lcp_width_threshold', ( $is_mobile ? 393 : 1920 ), $is_mobile, $url ); + + /** + * Filters the height threshold for the LCP beacon. + * + * @param int $height_threshold The height threshold. Default is 830 for mobile and 1080 for others. + * @param bool $is_mobile True if the current device is mobile, false otherwise. + * @param string $url The current URL. + * + * @return int The filtered height threshold. + */ + $height_threshold = apply_filters( 'rocket_lcp_height_threshold', ( $is_mobile ? 830 : 1080 ), $is_mobile, $url ); + $data = [ - 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'nonce' => wp_create_nonce( 'rocket_lcp' ), - 'url' => $url, - 'is_mobile' => $is_mobile, + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'nonce' => wp_create_nonce( 'rocket_lcp' ), + 'url' => $url, + 'is_mobile' => $is_mobile, + 'width_threshold' => $width_threshold, + 'height_threshold' => $height_threshold, ]; $inline_script = ''; diff --git a/tests/Fixtures/inc/Engine/Media/AboveTheFold/AJAX/Subscriber/checkLcpData.php b/tests/Fixtures/inc/Engine/Media/AboveTheFold/AJAX/Subscriber/checkLcpData.php new file mode 100644 index 0000000000..61a65ae4b2 --- /dev/null +++ b/tests/Fixtures/inc/Engine/Media/AboveTheFold/AJAX/Subscriber/checkLcpData.php @@ -0,0 +1,70 @@ + [ + 'config' => [ + 'filter' => false, + 'url' => 'http://example.org', + 'is_mobile' => false, + 'post' => [ + 'rocket_lcp_nonce' => wp_create_nonce( 'rocket_lcp' ), + 'action' => 'rocket_check_lcp', + 'url' => 'http://example.org', + 'is_mobile' => false, + ], + 'row' => [], + ], + 'expected' => [ + 'result' => false, + ], + ], + 'testShouldReturnExists' => [ + 'config' => [ + 'filter' => true, + 'url' => 'http://example.org', + 'is_mobile' => false, + 'post' => [ + 'rocket_lcp_nonce' => wp_create_nonce( 'rocket_lcp' ), + 'action' => 'rocket_check_lcp', + 'url' => 'http://example.org', + 'is_mobile' => false, + ], + 'row' => [ + 'status' => 'completed', + 'url' => 'http://example.org', + 'lcp' => json_encode( (object) [ + 'type' => 'img', + 'src' => 'http://example.org/wp-content/uploads/image.jpg', + ] ), + 'viewport' => json_encode( [ + 0 => (object) [ + 'type' => 'img', + 'src' => 'http://example.org/wp-content/uploads/image.jpg', + ], + ] ), + ], + 'row_exists' => true, + ], + 'expected' => [ + 'result' => true, + ], + ], + 'testShouldReturnNotExists' => [ + 'config' => [ + 'filter' => true, + 'url' => 'http://example.org', + 'is_mobile' => false, + 'post' => [ + 'rocket_lcp_nonce' => wp_create_nonce( 'rocket_lcp' ), + 'action' => 'rocket_check_lcp', + 'url' => 'http://example.org', + 'is_mobile' => false, + ], + 'row' => [], + 'row_exists' => false, + ], + 'expected' => [ + 'result' => false, + ], + ], +]; diff --git a/tests/Integration/inc/Engine/Media/AboveTheFold/AJAX/Subscriber/checkLcpData.php b/tests/Integration/inc/Engine/Media/AboveTheFold/AJAX/Subscriber/checkLcpData.php new file mode 100644 index 0000000000..c8ea52f363 --- /dev/null +++ b/tests/Integration/inc/Engine/Media/AboveTheFold/AJAX/Subscriber/checkLcpData.php @@ -0,0 +1,53 @@ +action = 'rocket_check_lcp'; + } + + /** + * $_POST is cleared in parent method + * + * @return void + */ + public function tear_down() { + remove_filter( 'rocket_above_the_fold_optimization', [ $this, 'set_allowed' ] ); + + parent::tear_down(); + } + + /** + * @dataProvider configTestData + */ + public function testShouldReturnExpected( $config, $expected ) { + $_POST = $config['post']; + + $this->allowed = $config['filter']; + + add_filter( 'rocket_above_the_fold_optimization', [ $this, 'set_allowed' ] ); + + if ( ! empty( $config['row'] ) ) { + self::addLcp( $config['row'] ); + } + + $result = $this->callAjaxAction(); + + $this->assertSame( $expected['result'], $result->success ); + } + public function set_allowed() { + return $this->allowed; + } +} From 1b02783827af241777f8412666251678138d6a36 Mon Sep 17 00:00:00 2001 From: Gael Robin Date: Thu, 11 Apr 2024 03:18:16 +0200 Subject: [PATCH 2/8] Fix integrations tests --- .../CDN/Subscriber/HTML/siteURL/rewrite.php | 2 +- .../HTML/siteURLWithPath/rewrite.php | 4 +-- .../Subscriber/HTML/output_w_beacon.html | 2 +- .../Minify/CSS/Subscriber/process.php | 12 ++++---- .../Minify/JS/Subscriber/process.php | 28 +++++++++---------- .../Hostings/WPEngine/Int/addFootprint.php | 6 ++-- ...disableImageDimensionsHeightPercentage.php | 4 +-- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/Fixtures/inc/Engine/CDN/Subscriber/HTML/siteURL/rewrite.php b/tests/Fixtures/inc/Engine/CDN/Subscriber/HTML/siteURL/rewrite.php index ae56c50d2a..6d59d6eee4 100644 --- a/tests/Fixtures/inc/Engine/CDN/Subscriber/HTML/siteURL/rewrite.php +++ b/tests/Fixtures/inc/Engine/CDN/Subscriber/HTML/siteURL/rewrite.php @@ -1033,7 +1033,7 @@ class="logoSite show-for-large" - + diff --git a/tests/Fixtures/inc/Engine/CDN/Subscriber/HTML/siteURLWithPath/rewrite.php b/tests/Fixtures/inc/Engine/CDN/Subscriber/HTML/siteURLWithPath/rewrite.php index 3fa6bfe13c..00b7d5d8ff 100644 --- a/tests/Fixtures/inc/Engine/CDN/Subscriber/HTML/siteURLWithPath/rewrite.php +++ b/tests/Fixtures/inc/Engine/CDN/Subscriber/HTML/siteURLWithPath/rewrite.php @@ -718,8 +718,8 @@ - + - \ No newline at end of file + diff --git a/tests/Fixtures/inc/Engine/Media/AboveTheFold/Frontend/Subscriber/HTML/output_w_beacon.html b/tests/Fixtures/inc/Engine/Media/AboveTheFold/Frontend/Subscriber/HTML/output_w_beacon.html index 53d94d59a2..70b0cb843a 100644 --- a/tests/Fixtures/inc/Engine/Media/AboveTheFold/Frontend/Subscriber/HTML/output_w_beacon.html +++ b/tests/Fixtures/inc/Engine/Media/AboveTheFold/Frontend/Subscriber/HTML/output_w_beacon.html @@ -3,5 +3,5 @@ Test - + diff --git a/tests/Fixtures/inc/Engine/Optimization/Minify/CSS/Subscriber/process.php b/tests/Fixtures/inc/Engine/Optimization/Minify/CSS/Subscriber/process.php index e263441e8c..b233d9a2c1 100644 --- a/tests/Fixtures/inc/Engine/Optimization/Minify/CSS/Subscriber/process.php +++ b/tests/Fixtures/inc/Engine/Optimization/Minify/CSS/Subscriber/process.php @@ -38,7 +38,7 @@ - + ', @@ -84,7 +84,7 @@ - + ', @@ -128,7 +128,7 @@ - + ', @@ -175,7 +175,7 @@ - + ', @@ -224,7 +224,7 @@ - + ', @@ -270,7 +270,7 @@ - + ', diff --git a/tests/Fixtures/inc/Engine/Optimization/Minify/JS/Subscriber/process.php b/tests/Fixtures/inc/Engine/Optimization/Minify/JS/Subscriber/process.php index 734dadec4d..0570f5e354 100644 --- a/tests/Fixtures/inc/Engine/Optimization/Minify/JS/Subscriber/process.php +++ b/tests/Fixtures/inc/Engine/Optimization/Minify/JS/Subscriber/process.php @@ -43,7 +43,7 @@ - + ', @@ -88,7 +88,7 @@ - + ', @@ -125,7 +125,7 @@ - + ', @@ -160,7 +160,7 @@ - + ', @@ -201,7 +201,7 @@ - + ', @@ -241,7 +241,7 @@ - + ', @@ -287,7 +287,7 @@ - + @@ -333,7 +333,7 @@ - + @@ -381,7 +381,7 @@ - + @@ -431,7 +431,7 @@ - + @@ -479,7 +479,7 @@ - + @@ -529,7 +529,7 @@ - + @@ -576,7 +576,7 @@ - + @@ -624,7 +624,7 @@ - + diff --git a/tests/Fixtures/inc/ThirdParty/Hostings/WPEngine/Int/addFootprint.php b/tests/Fixtures/inc/ThirdParty/Hostings/WPEngine/Int/addFootprint.php index d6cdde9776..25be5f62c7 100644 --- a/tests/Fixtures/inc/ThirdParty/Hostings/WPEngine/Int/addFootprint.php +++ b/tests/Fixtures/inc/ThirdParty/Hostings/WPEngine/Int/addFootprint.php @@ -7,7 +7,7 @@ '', 'expected' => 'Sample Page' . '' . - '' . + '' . "\n" . '', ], 'testWPEngineAddFootprintWithWhitelabel' => [ @@ -16,7 +16,7 @@ '', 'expected' => 'Sample Page' . '' . - '' . + '' . "\n" . '', ], 'testWPEngineAddFootprintNoHtmlShouldBailOut' => [ @@ -24,6 +24,6 @@ 'html' => 'Sample Page' . '', 'expected' => 'Sample Page' . - '', + '', ], ]; diff --git a/tests/Fixtures/inc/ThirdParty/Themes/Divi/Integration/disableImageDimensionsHeightPercentage.php b/tests/Fixtures/inc/ThirdParty/Themes/Divi/Integration/disableImageDimensionsHeightPercentage.php index 40a2e6d582..88c9c9fe15 100644 --- a/tests/Fixtures/inc/ThirdParty/Themes/Divi/Integration/disableImageDimensionsHeightPercentage.php +++ b/tests/Fixtures/inc/ThirdParty/Themes/Divi/Integration/disableImageDimensionsHeightPercentage.php @@ -20,7 +20,7 @@ - + @@ -96,7 +96,7 @@ ], 'html' => [ 'original' => '', - 'expected' => '', + 'expected' => '', ], ], ], From 58f8343e4a0bd8ce9a4183c6b8d9852c9660d574 Mon Sep 17 00:00:00 2001 From: Gael Robin Date: Mon, 15 Apr 2024 16:21:13 +0200 Subject: [PATCH 3/8] Comply feedback --- assets/js/lcp-beacon.js | 14 ++++++++------ inc/Engine/Media/AboveTheFold/AJAX/Controller.php | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/assets/js/lcp-beacon.js b/assets/js/lcp-beacon.js index 41830ed0be..5402d8ac6a 100644 --- a/assets/js/lcp-beacon.js +++ b/assets/js/lcp-beacon.js @@ -69,16 +69,18 @@ let performance_images = []; async function main() { // AJAX call to check if there are any records for the current URL + let data_check = new FormData(); + data_check.append('action', 'rocket_check_lcp'); + data_check.append('rocket_lcp_nonce', rocket_lcp_data.nonce); + data_check.append('url', rocket_lcp_data.url); + data_check.append('is_mobile', rocket_lcp_data.is_mobile); + const response = await fetch(rocket_lcp_data.ajax_url, { method: "POST", credentials: 'same-origin', - body: new URLSearchParams({ - action: 'rocket_check_lcp', - url: rocket_lcp_data.url, - rocket_lcp_nonce: rocket_lcp_data.nonce - }) + body: data_check }); - const lcp_data = await response.json(); + if ( true === lcp_data.success ) { console.log('Bailing out because data is already available'); return; diff --git a/inc/Engine/Media/AboveTheFold/AJAX/Controller.php b/inc/Engine/Media/AboveTheFold/AJAX/Controller.php index f8d9c1257e..124ac8795a 100644 --- a/inc/Engine/Media/AboveTheFold/AJAX/Controller.php +++ b/inc/Engine/Media/AboveTheFold/AJAX/Controller.php @@ -110,7 +110,7 @@ public function check_lcp_data() { } $url = isset( $_POST['url'] ) ? untrailingslashit( esc_url_raw( wp_unslash( $_POST['url'] ) ) ) : ''; - $is_mobile = isset( $_POST['is_mobile'] ) ? filter_var( wp_unslash( $_POST['is_mobile'] ), FILTER_VALIDATE_BOOL ) : false; + $is_mobile = isset( $_POST['is_mobile'] ) ? filter_var( wp_unslash( $_POST['is_mobile'] ), FILTER_VALIDATE_BOOLEAN ) : false; $row = $this->query->get_row( $url, $is_mobile ); From 538fbb13e773d876044354d1f29b67db1eea753e Mon Sep 17 00:00:00 2001 From: Gael Robin Date: Wed, 17 Apr 2024 03:25:30 +0200 Subject: [PATCH 4/8] Update lcp-beacon --- assets/js/lcp-beacon.js.min.map | 2 +- assets/js/lcp-beacon.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/lcp-beacon.js.min.map b/assets/js/lcp-beacon.js.min.map index 7b6a7e001a..bb8c3a77ef 100644 --- a/assets/js/lcp-beacon.js.min.map +++ b/assets/js/lcp-beacon.js.min.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["lcp-beacon.js"],"sourcesContent":["!function o(i,c,r){function a(t,e){if(!c[t]){if(!i[t]){var n=\"function\"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error(\"Cannot find module '\"+t+\"'\")).code=\"MODULE_NOT_FOUND\",n}n=c[t]={exports:{}},i[t][0].call(n.exports,function(e){return a(i[t][1][e]||e)},n,n.exports,o,i,c,r)}return c[t].exports}for(var l=\"function\"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0c[e].area){c.splice(e,0,{element:t,area:n,imageURL:o}),c.length=Math.min(i,c.length);break}c.length({element:e.element,imageURL:e.imageURL}))}let g=[];async function o(){const e=await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:new URLSearchParams({action:\"rocket_check_lcp\",url:rocket_lcp_data.url,rocket_lcp_nonce:rocket_lcp_data.nonce})});if(!0!==(await e.json()).success){var t=window.innerWidth||document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;if(t({src:e.imageURL,label:\"lcp\"}))):console.log(\"No LCP candidate found.\");for(var o=document.querySelectorAll(\"img\"),i=0;ie.src===c.src)||a!==document||g.push({src:c.src,label:\"above-the-fold\"})}}console.log(g);n=JSON.stringify(g);window.performance_images_json=n,console.log(n);const u=new FormData;u.append(\"action\",\"rocket_lcp\"),u.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),u.append(\"url\",rocket_lcp_data.url),u.append(\"is_mobile\",rocket_lcp_data.is_mobile),u.append(\"images\",n),u.append(\"status\",\"success\"),await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:u}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log(\"Bailing out because data is already available\")}\"loading\"!==document.readyState?(console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")):document.addEventListener(\"DOMContentLoaded\",async function(){console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")})},{}]},{},[1]);"],"file":"lcp-beacon.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["lcp-beacon.js"],"sourcesContent":["!function o(i,c,a){function r(t,e){if(!c[t]){if(!i[t]){var n=\"function\"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error(\"Cannot find module '\"+t+\"'\")).code=\"MODULE_NOT_FOUND\",n}n=c[t]={exports:{}},i[t][0].call(n.exports,function(e){return r(i[t][1][e]||e)},n,n.exports,o,i,c,a)}return c[t].exports}for(var l=\"function\"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0c[e].area){c.splice(e,0,{element:t,area:n,imageURL:o}),c.length=Math.min(i,c.length);break}c.length({element:e.element,imageURL:e.imageURL}))}let p=[];async function o(){let e=new FormData;e.append(\"action\",\"rocket_check_lcp\"),e.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),e.append(\"url\",rocket_lcp_data.url),e.append(\"is_mobile\",rocket_lcp_data.is_mobile);await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:e});if(!0!==lcp_data.success){var t=window.innerWidth||document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;if(t({src:e.imageURL,label:\"lcp\"}))):console.log(\"No LCP candidate found.\");for(var o=document.querySelectorAll(\"img\"),i=0;ie.src===c.src)||a!==document||p.push({src:c.src,label:\"above-the-fold\"})}}console.log(p);n=JSON.stringify(p);window.performance_images_json=n,console.log(n);const u=new FormData;u.append(\"action\",\"rocket_lcp\"),u.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),u.append(\"url\",rocket_lcp_data.url),u.append(\"is_mobile\",rocket_lcp_data.is_mobile),u.append(\"images\",n),u.append(\"status\",\"success\"),await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:u}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log(\"Bailing out because data is already available\")}\"loading\"!==document.readyState?(console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")):document.addEventListener(\"DOMContentLoaded\",async function(){console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")})},{}]},{},[1]);"],"file":"lcp-beacon.js"} \ No newline at end of file diff --git a/assets/js/lcp-beacon.min.js b/assets/js/lcp-beacon.min.js index a1fa186166..d68e87db3d 100644 --- a/assets/js/lcp-beacon.min.js +++ b/assets/js/lcp-beacon.min.js @@ -1,2 +1,2 @@ -!function o(i,c,r){function a(t,e){if(!c[t]){if(!i[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=c[t]={exports:{}},i[t][0].call(n.exports,function(e){return a(i[t][1][e]||e)},n,n.exports,o,i,c,r)}return c[t].exports}for(var l="function"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0c[e].area){c.splice(e,0,{element:t,area:n,imageURL:o}),c.length=Math.min(i,c.length);break}c.length({element:e.element,imageURL:e.imageURL}))}let g=[];async function o(){const e=await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:new URLSearchParams({action:"rocket_check_lcp",url:rocket_lcp_data.url,rocket_lcp_nonce:rocket_lcp_data.nonce})});if(!0!==(await e.json()).success){var t=window.innerWidth||document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;if(t({src:e.imageURL,label:"lcp"}))):console.log("No LCP candidate found.");for(var o=document.querySelectorAll("img"),i=0;ie.src===c.src)||a!==document||g.push({src:c.src,label:"above-the-fold"})}}console.log(g);n=JSON.stringify(g);window.performance_images_json=n,console.log(n);const u=new FormData;u.append("action","rocket_lcp"),u.append("rocket_lcp_nonce",rocket_lcp_data.nonce),u.append("url",rocket_lcp_data.url),u.append("is_mobile",rocket_lcp_data.is_mobile),u.append("images",n),u.append("status","success"),await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:u}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log("Bailing out because data is already available")}"loading"!==document.readyState?(console.time("extract"),setTimeout(o,500),console.timeEnd("extract")):document.addEventListener("DOMContentLoaded",async function(){console.time("extract"),setTimeout(o,500),console.timeEnd("extract")})},{}]},{},[1]); +!function o(i,c,a){function r(t,e){if(!c[t]){if(!i[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=c[t]={exports:{}},i[t][0].call(n.exports,function(e){return r(i[t][1][e]||e)},n,n.exports,o,i,c,a)}return c[t].exports}for(var l="function"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0c[e].area){c.splice(e,0,{element:t,area:n,imageURL:o}),c.length=Math.min(i,c.length);break}c.length({element:e.element,imageURL:e.imageURL}))}let p=[];async function o(){let e=new FormData;e.append("action","rocket_check_lcp"),e.append("rocket_lcp_nonce",rocket_lcp_data.nonce),e.append("url",rocket_lcp_data.url),e.append("is_mobile",rocket_lcp_data.is_mobile);await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:e});if(!0!==lcp_data.success){var t=window.innerWidth||document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;if(t({src:e.imageURL,label:"lcp"}))):console.log("No LCP candidate found.");for(var o=document.querySelectorAll("img"),i=0;ie.src===c.src)||a!==document||p.push({src:c.src,label:"above-the-fold"})}}console.log(p);n=JSON.stringify(p);window.performance_images_json=n,console.log(n);const u=new FormData;u.append("action","rocket_lcp"),u.append("rocket_lcp_nonce",rocket_lcp_data.nonce),u.append("url",rocket_lcp_data.url),u.append("is_mobile",rocket_lcp_data.is_mobile),u.append("images",n),u.append("status","success"),await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:u}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log("Bailing out because data is already available")}"loading"!==document.readyState?(console.time("extract"),setTimeout(o,500),console.timeEnd("extract")):document.addEventListener("DOMContentLoaded",async function(){console.time("extract"),setTimeout(o,500),console.timeEnd("extract")})},{}]},{},[1]); //# sourceMappingURL=lcp-beacon.js.map From ed582a82155a6929683f544b25c45b63713ac457 Mon Sep 17 00:00:00 2001 From: Gael Robin Date: Fri, 19 Apr 2024 09:54:45 +0200 Subject: [PATCH 5/8] Change conditions to bail out --- assets/js/lcp-beacon.js | 5 +++-- assets/js/lcp-beacon.js.min.map | 2 +- assets/js/lcp-beacon.min.js | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/assets/js/lcp-beacon.js b/assets/js/lcp-beacon.js index 8edd6f2384..2b3159ca2e 100644 --- a/assets/js/lcp-beacon.js +++ b/assets/js/lcp-beacon.js @@ -94,8 +94,9 @@ async function main() { // Check screen size const screenWidth = window.innerWidth || document.documentElement.clientWidth; const screenHeight = window.innerHeight || document.documentElement.clientHeight; - if ( - ( ( screenWidth < rocket_lcp_data.width_threshold || screenHeight < rocket_lcp_data.height_threshold ) ) ) { + if ( ( rocket_lcp_data.is_mobile && ( screenWidth > rocket_lcp_data.width_threshold || screenHeight > rocket_lcp_data.height_threshold ) ) || + ( ! rocket_lcp_data.is_mobile && ( screenWidth < rocket_lcp_data.width_threshold || screenHeight < rocket_lcp_data.height_threshold ) ) ) + { console.log('Bailing out because screen size is not acceptable'); return; } diff --git a/assets/js/lcp-beacon.js.min.map b/assets/js/lcp-beacon.js.min.map index bb8c3a77ef..7c91235742 100644 --- a/assets/js/lcp-beacon.js.min.map +++ b/assets/js/lcp-beacon.js.min.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["lcp-beacon.js"],"sourcesContent":["!function o(i,c,a){function r(t,e){if(!c[t]){if(!i[t]){var n=\"function\"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error(\"Cannot find module '\"+t+\"'\")).code=\"MODULE_NOT_FOUND\",n}n=c[t]={exports:{}},i[t][0].call(n.exports,function(e){return r(i[t][1][e]||e)},n,n.exports,o,i,c,a)}return c[t].exports}for(var l=\"function\"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0c[e].area){c.splice(e,0,{element:t,area:n,imageURL:o}),c.length=Math.min(i,c.length);break}c.length({element:e.element,imageURL:e.imageURL}))}let p=[];async function o(){let e=new FormData;e.append(\"action\",\"rocket_check_lcp\"),e.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),e.append(\"url\",rocket_lcp_data.url),e.append(\"is_mobile\",rocket_lcp_data.is_mobile);await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:e});if(!0!==lcp_data.success){var t=window.innerWidth||document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;if(t({src:e.imageURL,label:\"lcp\"}))):console.log(\"No LCP candidate found.\");for(var o=document.querySelectorAll(\"img\"),i=0;ie.src===c.src)||a!==document||p.push({src:c.src,label:\"above-the-fold\"})}}console.log(p);n=JSON.stringify(p);window.performance_images_json=n,console.log(n);const u=new FormData;u.append(\"action\",\"rocket_lcp\"),u.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),u.append(\"url\",rocket_lcp_data.url),u.append(\"is_mobile\",rocket_lcp_data.is_mobile),u.append(\"images\",n),u.append(\"status\",\"success\"),await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:u}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log(\"Bailing out because data is already available\")}\"loading\"!==document.readyState?(console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")):document.addEventListener(\"DOMContentLoaded\",async function(){console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")})},{}]},{},[1]);"],"file":"lcp-beacon.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["lcp-beacon.js"],"sourcesContent":["!function o(i,c,a){function r(t,e){if(!c[t]){if(!i[t]){var n=\"function\"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error(\"Cannot find module '\"+t+\"'\")).code=\"MODULE_NOT_FOUND\",n}n=c[t]={exports:{}},i[t][0].call(n.exports,function(e){return r(i[t][1][e]||e)},n,n.exports,o,i,c,a)}return c[t].exports}for(var l=\"function\"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0c[e].area){c.splice(e,0,{element:t,area:n,imageURL:o}),c.length=Math.min(i,c.length);break}c.length({element:e.element,imageURL:e.imageURL}))}let p=[];async function o(){let e=new FormData;e.append(\"action\",\"rocket_check_lcp\"),e.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),e.append(\"url\",rocket_lcp_data.url),e.append(\"is_mobile\",rocket_lcp_data.is_mobile);await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:e});if(!0!==lcp_data.success){var t=window.innerWidth||document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;if(rocket_lcp_data.is_mobile&&(t>rocket_lcp_data.width_threshold||n>rocket_lcp_data.height_threshold)||!rocket_lcp_data.is_mobile&&(t({src:e.imageURL,label:\"lcp\"}))):console.log(\"No LCP candidate found.\");for(var o=document.querySelectorAll(\"img\"),i=0;ie.src===c.src)||a!==document||p.push({src:c.src,label:\"above-the-fold\"})}}console.log(p);n=JSON.stringify(p);window.performance_images_json=n,console.log(n);const s=new FormData;s.append(\"action\",\"rocket_lcp\"),s.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),s.append(\"url\",rocket_lcp_data.url),s.append(\"is_mobile\",rocket_lcp_data.is_mobile),s.append(\"images\",n),s.append(\"status\",\"success\"),await fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:s}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log(\"Bailing out because data is already available\")}\"loading\"!==document.readyState?(console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")):document.addEventListener(\"DOMContentLoaded\",async function(){console.time(\"extract\"),setTimeout(o,500),console.timeEnd(\"extract\")})},{}]},{},[1]);"],"file":"lcp-beacon.js"} diff --git a/assets/js/lcp-beacon.min.js b/assets/js/lcp-beacon.min.js index d68e87db3d..58dd81b7c9 100644 --- a/assets/js/lcp-beacon.min.js +++ b/assets/js/lcp-beacon.min.js @@ -1,2 +1,2 @@ -!function o(i,c,a){function r(t,e){if(!c[t]){if(!i[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=c[t]={exports:{}},i[t][0].call(n.exports,function(e){return r(i[t][1][e]||e)},n,n.exports,o,i,c,a)}return c[t].exports}for(var l="function"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0c[e].area){c.splice(e,0,{element:t,area:n,imageURL:o}),c.length=Math.min(i,c.length);break}c.length({element:e.element,imageURL:e.imageURL}))}let p=[];async function o(){let e=new FormData;e.append("action","rocket_check_lcp"),e.append("rocket_lcp_nonce",rocket_lcp_data.nonce),e.append("url",rocket_lcp_data.url),e.append("is_mobile",rocket_lcp_data.is_mobile);await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:e});if(!0!==lcp_data.success){var t=window.innerWidth||document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;if(t({src:e.imageURL,label:"lcp"}))):console.log("No LCP candidate found.");for(var o=document.querySelectorAll("img"),i=0;ie.src===c.src)||a!==document||p.push({src:c.src,label:"above-the-fold"})}}console.log(p);n=JSON.stringify(p);window.performance_images_json=n,console.log(n);const u=new FormData;u.append("action","rocket_lcp"),u.append("rocket_lcp_nonce",rocket_lcp_data.nonce),u.append("url",rocket_lcp_data.url),u.append("is_mobile",rocket_lcp_data.is_mobile),u.append("images",n),u.append("status","success"),await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:u}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log("Bailing out because data is already available")}"loading"!==document.readyState?(console.time("extract"),setTimeout(o,500),console.timeEnd("extract")):document.addEventListener("DOMContentLoaded",async function(){console.time("extract"),setTimeout(o,500),console.timeEnd("extract")})},{}]},{},[1]); +!function o(i,c,a){function r(t,e){if(!c[t]){if(!i[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=c[t]={exports:{}},i[t][0].call(n.exports,function(e){return r(i[t][1][e]||e)},n,n.exports,o,i,c,a)}return c[t].exports}for(var l="function"==typeof require&&require,e=0;e{var e=t.getBoundingClientRect();if(0c[e].area){c.splice(e,0,{element:t,area:n,imageURL:o}),c.length=Math.min(i,c.length);break}c.length({element:e.element,imageURL:e.imageURL}))}let p=[];async function o(){let e=new FormData;e.append("action","rocket_check_lcp"),e.append("rocket_lcp_nonce",rocket_lcp_data.nonce),e.append("url",rocket_lcp_data.url),e.append("is_mobile",rocket_lcp_data.is_mobile);await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:e});if(!0!==lcp_data.success){var t=window.innerWidth||document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;if(rocket_lcp_data.is_mobile&&(t>rocket_lcp_data.width_threshold||n>rocket_lcp_data.height_threshold)||!rocket_lcp_data.is_mobile&&(t({src:e.imageURL,label:"lcp"}))):console.log("No LCP candidate found.");for(var o=document.querySelectorAll("img"),i=0;ie.src===c.src)||a!==document||p.push({src:c.src,label:"above-the-fold"})}}console.log(p);n=JSON.stringify(p);window.performance_images_json=n,console.log(n);const s=new FormData;s.append("action","rocket_lcp"),s.append("rocket_lcp_nonce",rocket_lcp_data.nonce),s.append("url",rocket_lcp_data.url),s.append("is_mobile",rocket_lcp_data.is_mobile),s.append("images",n),s.append("status","success"),await fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:s}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log("Bailing out because data is already available")}"loading"!==document.readyState?(console.time("extract"),setTimeout(o,500),console.timeEnd("extract")):document.addEventListener("DOMContentLoaded",async function(){console.time("extract"),setTimeout(o,500),console.timeEnd("extract")})},{}]},{},[1]); //# sourceMappingURL=lcp-beacon.js.map From b174327e0688b4112697702855636288c94b3b58 Mon Sep 17 00:00:00 2001 From: Gael Robin Date: Thu, 25 Apr 2024 04:19:30 +0200 Subject: [PATCH 6/8] Update lcp-beacon.min.js --- assets/js/lcp-beacon.js.min.map | 2 +- assets/js/lcp-beacon.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/lcp-beacon.js.min.map b/assets/js/lcp-beacon.js.min.map index e9c7dd776a..69ee8df1f0 100644 --- a/assets/js/lcp-beacon.js.min.map +++ b/assets/js/lcp-beacon.js.min.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["lcp-beacon.js"],"sourcesContent":["!function n(c,o,i){function s(t,e){if(!o[t]){if(!c[t]){var r=\"function\"==typeof require&&require;if(!e&&r)return r(t,!0);if(l)return l(t,!0);throw(r=new Error(\"Cannot find module '\"+t+\"'\")).code=\"MODULE_NOT_FOUND\",r}r=o[t]={exports:{}},c[t][0].call(r.exports,function(e){return s(c[t][1][e]||e)},r,r.exports,n,c,o,i)}return o[t].exports}for(var l=\"function\"==typeof require&&require,e=0;e{var t=e.getBoundingClientRect();return{element:e,rect:t}}).filter(e=>{return 0({item:e,area:function(e){var t=Math.min(e.width,(window.innerWidth||document.documentElement.clientWidth)-e.left),e=Math.min(e.height,(window.innerHeight||document.documentElement.clientHeight)-e.top);return t*e}(e.rect),elementInfo:c(e.element)})).sort((e,t)=>t.area-e.area).slice(0,e);return r.map(e=>({element:e.item.element,elementInfo:e.elementInfo}))}function c(e){var t=e.nodeName.toLowerCase();const r={type:\"\",src:\"\",srcset:\"\",sizes:\"\",sources:[],bg_set:[],current_src:\"\"};if(\"img\"===t&&e.srcset)r.type=\"img-srcset\",r.src=e.src,r.srcset=e.srcset,r.sizes=e.sizes,r.current_src=e.currentSrc;else if(\"img\"===t)r.type=\"img\",r.src=e.src,r.current_src=e.currentSrc;else if(\"video\"===t){r.type=\"img\";var n=e.querySelector(\"source\");r.src=e.poster||(n?n.src:\"\"),r.current_src=r.src}else if(\"svg\"===t){const c=e.querySelector(\"image\");c&&(r.type=\"img\",r.src=c.getAttribute(\"href\")||\"\",r.current_src=r.src)}else if(\"picture\"===t){r.type=\"picture\";t=e.querySelector(\"img:not(picture>img)\");r.src=t?t.src:\"\",r.sources=Array.from(e.querySelectorAll(\"source\")).map(e=>({srcset:e.srcset||\"\",media:e.media||\"\"}))}else{const o=window.getComputedStyle(e,null),i=[o.getPropertyValue(\"background-image\"),getComputedStyle(e,\":after\").getPropertyValue(\"background-image\"),getComputedStyle(e,\":before\").getPropertyValue(\"background-image\")],s=i.filter(e=>\"none\"!==e).join(\"\");if(r.type=\"bg-img\",s.includes(\"image-set(\")&&(r.type=\"bg-img-set\"),!s||\"\"===s)return null;const l=[...s.matchAll(/url\\(\\s*?['\"]?\\s*?(\\S+?)\\s*?[\"']?\\s*?\\)\\s*?([a-zA-Z0-9\\s]*[x|dpcm|dpi|dppx]?)/gi)];r.bg_set=l.map(e=>e[1]?{src:e[1].trim()+(e[2]?\" \"+e[2].trim():\"\")}:{}),r.bg_set.every(e=>\"\"===e.src)&&(r.bg_set=l.map(e=>e[1]?{src:e[1].trim()}:{})),0null!==e.elementInfo);t?o=[{...t.elementInfo,label:\"lcp\"}]:console.log(\"No LCP candidate found.\"),e.forEach(e=>{var{element:t,elementInfo:e}=e;!function(e,t){const r=c(e);if(null===r)return!1;var n=\"img\"===r.type||\"img-srcset\"===r.type||\"video\"===r.type,e=\"bg-img\"===r.type||\"bg-img-set\"===r.type||\"picture\"===r.type;return(n||e)&&t.some(e=>e.src===r.src)}(t,o)&&o.push({...e,label:\"above-the-fold\"})});t=JSON.stringify(o);window.performance_images_json=t;rocket_lcp_data.nonce,rocket_lcp_data.url,rocket_lcp_data.is_mobile;const r=new FormData;r.append(\"action\",\"rocket_lcp\"),r.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),r.append(\"url\",rocket_lcp_data.url),r.append(\"is_mobile\",rocket_lcp_data.is_mobile),r.append(\"images\",t),r.append(\"status\",\"success\"),fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:r}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}\"loading\"!==document.readyState?(console.time(\"extract\"),setTimeout(i,500),console.timeEnd(\"extract\")):document.addEventListener(\"DOMContentLoaded\",function(){console.time(\"extract\"),setTimeout(i,500),console.timeEnd(\"extract\")})},{}]},{},[1]);"],"file":"lcp-beacon.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["lcp-beacon.js"],"sourcesContent":["!function n(c,o,i){function s(t,e){if(!o[t]){if(!c[t]){var r=\"function\"==typeof require&&require;if(!e&&r)return r(t,!0);if(l)return l(t,!0);throw(r=new Error(\"Cannot find module '\"+t+\"'\")).code=\"MODULE_NOT_FOUND\",r}r=o[t]={exports:{}},c[t][0].call(r.exports,function(e){return s(c[t][1][e]||e)},r,r.exports,n,c,o,i)}return o[t].exports}for(var l=\"function\"==typeof require&&require,e=0;e{var t=e.getBoundingClientRect();return{element:e,rect:t}}).filter(e=>{return 0({item:e,area:function(e){var t=Math.min(e.width,(window.innerWidth||document.documentElement.clientWidth)-e.left),e=Math.min(e.height,(window.innerHeight||document.documentElement.clientHeight)-e.top);return t*e}(e.rect),elementInfo:s(e.element)})).sort((e,t)=>t.area-e.area).slice(0,e);return r.map(e=>({element:e.item.element,elementInfo:e.elementInfo}))}function s(e){var t=e.nodeName.toLowerCase();const r={type:\"\",src:\"\",srcset:\"\",sizes:\"\",sources:[],bg_set:[],current_src:\"\"};if(\"img\"===t&&e.srcset)r.type=\"img-srcset\",r.src=e.src,r.srcset=e.srcset,r.sizes=e.sizes,r.current_src=e.currentSrc;else if(\"img\"===t)r.type=\"img\",r.src=e.src,r.current_src=e.currentSrc;else if(\"video\"===t){r.type=\"img\";var n=e.querySelector(\"source\");r.src=e.poster||(n?n.src:\"\"),r.current_src=r.src}else if(\"svg\"===t){const c=e.querySelector(\"image\");c&&(r.type=\"img\",r.src=c.getAttribute(\"href\")||\"\",r.current_src=r.src)}else if(\"picture\"===t){r.type=\"picture\";t=e.querySelector(\"img:not(picture>img)\");r.src=t?t.src:\"\",r.sources=Array.from(e.querySelectorAll(\"source\")).map(e=>({srcset:e.srcset||\"\",media:e.media||\"\"}))}else{const o=window.getComputedStyle(e,null),i=[o.getPropertyValue(\"background-image\"),getComputedStyle(e,\":after\").getPropertyValue(\"background-image\"),getComputedStyle(e,\":before\").getPropertyValue(\"background-image\")],s=i.filter(e=>\"none\"!==e).join(\"\");if(r.type=\"bg-img\",s.includes(\"image-set(\")&&(r.type=\"bg-img-set\"),!s||\"\"===s)return null;const l=[...s.matchAll(/url\\(\\s*?['\"]?\\s*?(\\S+?)\\s*?[\"']?\\s*?\\)\\s*?([a-zA-Z0-9\\s]*[x|dpcm|dpi|dppx]?)/gi)];r.bg_set=l.map(e=>e[1]?{src:e[1].trim()+(e[2]?\" \"+e[2].trim():\"\")}:{}),r.bg_set.every(e=>\"\"===e.src)&&(r.bg_set=l.map(e=>e[1]?{src:e[1].trim()}:{})),0rocket_lcp_data.width_threshold||r>rocket_lcp_data.height_threshold)||!rocket_lcp_data.is_mobile&&(t({src:e.imageURL,label:\"lcp\"}))):console.log(\"No LCP candidate found.\");const c=i(1/0);r=c.find(e=>null!==e.elementInfo);r?l=[{...r.elementInfo,label:\"lcp\"}]:console.log(\"No LCP candidate found.\"),c.forEach(e=>{var{element:t,elementInfo:e}=e;!function(e,t){const r=s(e);if(null===r)return!1;var n=\"img\"===r.type||\"img-srcset\"===r.type||\"video\"===r.type,e=\"bg-img\"===r.type||\"bg-img-set\"===r.type||\"picture\"===r.type;return(n||e)&&t.some(e=>e.src===r.src)}(t,l)&&l.push({...e,label:\"above-the-fold\"})});r=JSON.stringify(l);window.performance_images_json=r;rocket_lcp_data.nonce,rocket_lcp_data.url,rocket_lcp_data.is_mobile;const o=new FormData;o.append(\"action\",\"rocket_lcp\"),o.append(\"rocket_lcp_nonce\",rocket_lcp_data.nonce),o.append(\"url\",rocket_lcp_data.url),o.append(\"is_mobile\",rocket_lcp_data.is_mobile),o.append(\"images\",r),o.append(\"status\",\"success\"),fetch(rocket_lcp_data.ajax_url,{method:\"POST\",credentials:\"same-origin\",body:o}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log(\"Bailing out because data is already available\")}\"loading\"!==document.readyState?(console.time(\"extract\"),setTimeout(n,500),console.timeEnd(\"extract\")):document.addEventListener(\"DOMContentLoaded\",function(){console.time(\"extract\"),setTimeout(n,500),console.timeEnd(\"extract\")})},{}]},{},[1]);"],"file":"lcp-beacon.js"} \ No newline at end of file diff --git a/assets/js/lcp-beacon.min.js b/assets/js/lcp-beacon.min.js index cc53d770e6..b8313af89b 100644 --- a/assets/js/lcp-beacon.min.js +++ b/assets/js/lcp-beacon.min.js @@ -1,2 +1,2 @@ -!function n(c,o,i){function s(t,e){if(!o[t]){if(!c[t]){var r="function"==typeof require&&require;if(!e&&r)return r(t,!0);if(l)return l(t,!0);throw(r=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",r}r=o[t]={exports:{}},c[t][0].call(r.exports,function(e){return s(c[t][1][e]||e)},r,r.exports,n,c,o,i)}return o[t].exports}for(var l="function"==typeof require&&require,e=0;e{var t=e.getBoundingClientRect();return{element:e,rect:t}}).filter(e=>{return 0({item:e,area:function(e){var t=Math.min(e.width,(window.innerWidth||document.documentElement.clientWidth)-e.left),e=Math.min(e.height,(window.innerHeight||document.documentElement.clientHeight)-e.top);return t*e}(e.rect),elementInfo:c(e.element)})).sort((e,t)=>t.area-e.area).slice(0,e);return r.map(e=>({element:e.item.element,elementInfo:e.elementInfo}))}function c(e){var t=e.nodeName.toLowerCase();const r={type:"",src:"",srcset:"",sizes:"",sources:[],bg_set:[],current_src:""};if("img"===t&&e.srcset)r.type="img-srcset",r.src=e.src,r.srcset=e.srcset,r.sizes=e.sizes,r.current_src=e.currentSrc;else if("img"===t)r.type="img",r.src=e.src,r.current_src=e.currentSrc;else if("video"===t){r.type="img";var n=e.querySelector("source");r.src=e.poster||(n?n.src:""),r.current_src=r.src}else if("svg"===t){const c=e.querySelector("image");c&&(r.type="img",r.src=c.getAttribute("href")||"",r.current_src=r.src)}else if("picture"===t){r.type="picture";t=e.querySelector("img:not(picture>img)");r.src=t?t.src:"",r.sources=Array.from(e.querySelectorAll("source")).map(e=>({srcset:e.srcset||"",media:e.media||""}))}else{const o=window.getComputedStyle(e,null),i=[o.getPropertyValue("background-image"),getComputedStyle(e,":after").getPropertyValue("background-image"),getComputedStyle(e,":before").getPropertyValue("background-image")],s=i.filter(e=>"none"!==e).join("");if(r.type="bg-img",s.includes("image-set(")&&(r.type="bg-img-set"),!s||""===s)return null;const l=[...s.matchAll(/url\(\s*?['"]?\s*?(\S+?)\s*?["']?\s*?\)\s*?([a-zA-Z0-9\s]*[x|dpcm|dpi|dppx]?)/gi)];r.bg_set=l.map(e=>e[1]?{src:e[1].trim()+(e[2]?" "+e[2].trim():"")}:{}),r.bg_set.every(e=>""===e.src)&&(r.bg_set=l.map(e=>e[1]?{src:e[1].trim()}:{})),0null!==e.elementInfo);t?o=[{...t.elementInfo,label:"lcp"}]:console.log("No LCP candidate found."),e.forEach(e=>{var{element:t,elementInfo:e}=e;!function(e,t){const r=c(e);if(null===r)return!1;var n="img"===r.type||"img-srcset"===r.type||"video"===r.type,e="bg-img"===r.type||"bg-img-set"===r.type||"picture"===r.type;return(n||e)&&t.some(e=>e.src===r.src)}(t,o)&&o.push({...e,label:"above-the-fold"})});t=JSON.stringify(o);window.performance_images_json=t;rocket_lcp_data.nonce,rocket_lcp_data.url,rocket_lcp_data.is_mobile;const r=new FormData;r.append("action","rocket_lcp"),r.append("rocket_lcp_nonce",rocket_lcp_data.nonce),r.append("url",rocket_lcp_data.url),r.append("is_mobile",rocket_lcp_data.is_mobile),r.append("images",t),r.append("status","success"),fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:r}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}"loading"!==document.readyState?(console.time("extract"),setTimeout(i,500),console.timeEnd("extract")):document.addEventListener("DOMContentLoaded",function(){console.time("extract"),setTimeout(i,500),console.timeEnd("extract")})},{}]},{},[1]); +!function n(c,o,i){function s(t,e){if(!o[t]){if(!c[t]){var r="function"==typeof require&&require;if(!e&&r)return r(t,!0);if(l)return l(t,!0);throw(r=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",r}r=o[t]={exports:{}},c[t][0].call(r.exports,function(e){return s(c[t][1][e]||e)},r,r.exports,n,c,o,i)}return o[t].exports}for(var l="function"==typeof require&&require,e=0;e{var t=e.getBoundingClientRect();return{element:e,rect:t}}).filter(e=>{return 0({item:e,area:function(e){var t=Math.min(e.width,(window.innerWidth||document.documentElement.clientWidth)-e.left),e=Math.min(e.height,(window.innerHeight||document.documentElement.clientHeight)-e.top);return t*e}(e.rect),elementInfo:s(e.element)})).sort((e,t)=>t.area-e.area).slice(0,e);return r.map(e=>({element:e.item.element,elementInfo:e.elementInfo}))}function s(e){var t=e.nodeName.toLowerCase();const r={type:"",src:"",srcset:"",sizes:"",sources:[],bg_set:[],current_src:""};if("img"===t&&e.srcset)r.type="img-srcset",r.src=e.src,r.srcset=e.srcset,r.sizes=e.sizes,r.current_src=e.currentSrc;else if("img"===t)r.type="img",r.src=e.src,r.current_src=e.currentSrc;else if("video"===t){r.type="img";var n=e.querySelector("source");r.src=e.poster||(n?n.src:""),r.current_src=r.src}else if("svg"===t){const c=e.querySelector("image");c&&(r.type="img",r.src=c.getAttribute("href")||"",r.current_src=r.src)}else if("picture"===t){r.type="picture";t=e.querySelector("img:not(picture>img)");r.src=t?t.src:"",r.sources=Array.from(e.querySelectorAll("source")).map(e=>({srcset:e.srcset||"",media:e.media||""}))}else{const o=window.getComputedStyle(e,null),i=[o.getPropertyValue("background-image"),getComputedStyle(e,":after").getPropertyValue("background-image"),getComputedStyle(e,":before").getPropertyValue("background-image")],s=i.filter(e=>"none"!==e).join("");if(r.type="bg-img",s.includes("image-set(")&&(r.type="bg-img-set"),!s||""===s)return null;const l=[...s.matchAll(/url\(\s*?['"]?\s*?(\S+?)\s*?["']?\s*?\)\s*?([a-zA-Z0-9\s]*[x|dpcm|dpi|dppx]?)/gi)];r.bg_set=l.map(e=>e[1]?{src:e[1].trim()+(e[2]?" "+e[2].trim():"")}:{}),r.bg_set.every(e=>""===e.src)&&(r.bg_set=l.map(e=>e[1]?{src:e[1].trim()}:{})),0rocket_lcp_data.width_threshold||r>rocket_lcp_data.height_threshold)||!rocket_lcp_data.is_mobile&&(t({src:e.imageURL,label:"lcp"}))):console.log("No LCP candidate found.");const c=i(1/0);r=c.find(e=>null!==e.elementInfo);r?l=[{...r.elementInfo,label:"lcp"}]:console.log("No LCP candidate found."),c.forEach(e=>{var{element:t,elementInfo:e}=e;!function(e,t){const r=s(e);if(null===r)return!1;var n="img"===r.type||"img-srcset"===r.type||"video"===r.type,e="bg-img"===r.type||"bg-img-set"===r.type||"picture"===r.type;return(n||e)&&t.some(e=>e.src===r.src)}(t,l)&&l.push({...e,label:"above-the-fold"})});r=JSON.stringify(l);window.performance_images_json=r;rocket_lcp_data.nonce,rocket_lcp_data.url,rocket_lcp_data.is_mobile;const o=new FormData;o.append("action","rocket_lcp"),o.append("rocket_lcp_nonce",rocket_lcp_data.nonce),o.append("url",rocket_lcp_data.url),o.append("is_mobile",rocket_lcp_data.is_mobile),o.append("images",r),o.append("status","success"),fetch(rocket_lcp_data.ajax_url,{method:"POST",credentials:"same-origin",body:o}).then(e=>e.json()).then(e=>{console.log(e)}).catch(e=>{console.error(e)})}}else console.log("Bailing out because data is already available")}"loading"!==document.readyState?(console.time("extract"),setTimeout(n,500),console.timeEnd("extract")):document.addEventListener("DOMContentLoaded",function(){console.time("extract"),setTimeout(n,500),console.timeEnd("extract")})},{}]},{},[1]); //# sourceMappingURL=lcp-beacon.js.map From bad9d46c97731367ebd9774df1dc79e12c793aa9 Mon Sep 17 00:00:00 2001 From: Gael Robin Date: Thu, 25 Apr 2024 04:22:21 +0200 Subject: [PATCH 7/8] Fix linter --- .../Media/AboveTheFold/Frontend/Controller.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php index 9326f99f77..0a7bed1a8f 100644 --- a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php +++ b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php @@ -372,13 +372,13 @@ public function inject_beacon( $html, $url, $is_mobile ): string { $height_threshold = apply_filters( 'rocket_lcp_height_threshold', ( $is_mobile ? 830 : 1080 ), $is_mobile, $url ); $data = [ - 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'nonce' => wp_create_nonce( 'rocket_lcp' ), - 'url' => $url, - 'is_mobile' => $is_mobile, - 'elements' => $this->lcp_atf_elements(), - 'width_threshold' => $width_threshold, - 'height_threshold' => $height_threshold, + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'nonce' => wp_create_nonce( 'rocket_lcp' ), + 'url' => $url, + 'is_mobile' => $is_mobile, + 'elements' => $this->lcp_atf_elements(), + 'width_threshold' => $width_threshold, + 'height_threshold' => $height_threshold, ]; $inline_script = ''; From d7836388ec00cf3a421be9e2bdef545ba819a8a3 Mon Sep 17 00:00:00 2001 From: Gael Robin Date: Thu, 25 Apr 2024 05:13:58 +0200 Subject: [PATCH 8/8] Fix linter --- inc/functions/htaccess.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/inc/functions/htaccess.php b/inc/functions/htaccess.php index cc502c0370..79953e4f49 100755 --- a/inc/functions/htaccess.php +++ b/inc/functions/htaccess.php @@ -38,11 +38,11 @@ function flush_rocket_htaccess( $remove_rules = false ) { // phpcs:ignore WordPr } if ( ! file_exists( $filename ) ) { - if ( ! is_writable( dirname( $filename ) ) ) { + if ( ! is_writable( dirname( $filename ) ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_is_writable return false; } - if ( ! touch( $filename ) ) { + if ( ! touch( $filename ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_touch return false; } @@ -50,9 +50,9 @@ function flush_rocket_htaccess( $remove_rules = false ) { // phpcs:ignore WordPr $perms = fileperms( $filename ); if ( $perms ) { - chmod( $filename, $perms | 0644 ); + chmod( $filename, $perms | 0644 ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_chmod } - } elseif ( ! is_writable( $filename ) ) { + } elseif ( ! is_writable( $filename ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_is_writable return false; } @@ -63,7 +63,7 @@ function flush_rocket_htaccess( $remove_rules = false ) { // phpcs:ignore WordPr $start_marker = '# BEGIN WP Rocket'; $end_marker = '# END WP Rocket'; - $pointer = fopen( $filename, 'r+' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen + $pointer = fopen( $filename, 'r+' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen if ( ! $pointer ) { return false; @@ -106,7 +106,7 @@ function flush_rocket_htaccess( $remove_rules = false ) { // phpcs:ignore WordPr // Check to see if there was a change. if ( $existing_lines === $insertion ) { flock( $pointer, LOCK_UN ); - fclose( $pointer ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose + fclose( $pointer ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose return true; } @@ -148,7 +148,7 @@ function flush_rocket_htaccess( $remove_rules = false ) { // phpcs:ignore WordPr // Write to the start of the file, and truncate it to that length. fseek( $pointer, 0 ); - $bytes = fwrite( $pointer, $new_file_data ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite + $bytes = fwrite( $pointer, $new_file_data ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite if ( $bytes ) { ftruncate( $pointer, ftell( $pointer ) ); @@ -156,7 +156,7 @@ function flush_rocket_htaccess( $remove_rules = false ) { // phpcs:ignore WordPr fflush( $pointer ); flock( $pointer, LOCK_UN ); - fclose( $pointer ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose + fclose( $pointer ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose return (bool) $bytes; }