From 2033d448b25012ce9134b6fc329e851ca852e1fc Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 18 Dec 2024 16:27:38 -0800 Subject: [PATCH 1/2] Remove erroneous check for resource initiatorType when considering whether to submit external background image --- plugins/image-prioritizer/detect.js | 36 ----------------------------- 1 file changed, 36 deletions(-) diff --git a/plugins/image-prioritizer/detect.js b/plugins/image-prioritizer/detect.js index 54fe64d09..4f5f5b158 100644 --- a/plugins/image-prioritizer/detect.js +++ b/plugins/image-prioritizer/detect.js @@ -77,27 +77,6 @@ export async function initialize( { isDebug, onLCP } ) { ); } -/** - * Gets the performance resource entry for a given URL. - * - * @since 0.3.0 - * - * @param {string} url - Resource URL. - * @return {PerformanceResourceTiming|null} Resource entry or null. - */ -function getPerformanceResourceByURL( url ) { - const entries = - /** @type PerformanceResourceTiming[] */ performance.getEntriesByType( - 'resource' - ); - for ( const entry of entries ) { - if ( entry.name === url ) { - return entry; - } - } - return null; -} - /** * Handles a new LCP metric being reported. * @@ -129,21 +108,6 @@ function handleLCPMetric( metric, isDebug ) { continue; } - // Now only consider proceeding with the URL if its loading was initiated with stylesheet or preload link. - const resourceEntry = getPerformanceResourceByURL( entry.url ); - if ( - ! resourceEntry || - ! [ 'css', 'link' ].includes( resourceEntry.initiatorType ) - ) { - if ( isDebug ) { - warn( - `Skipped considering URL (${ entry.url }) due to unexpected performance resource timing entry:`, - resourceEntry - ); - } - return; - } - // Skip URLs that are excessively long. This is the maxLength defined in image_prioritizer_add_element_item_schema_properties(). if ( entry.url.length > 500 ) { if ( isDebug ) { From eee6bf2b53dc0f05d8981f30b03d02fbccec8ae3 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 18 Dec 2024 17:14:19 -0800 Subject: [PATCH 2/2] Remove unused warn() --- plugins/image-prioritizer/detect.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/plugins/image-prioritizer/detect.js b/plugins/image-prioritizer/detect.js index 4f5f5b158..63c1c2770 100644 --- a/plugins/image-prioritizer/detect.js +++ b/plugins/image-prioritizer/detect.js @@ -43,18 +43,6 @@ function log( ...message ) { console.log( consoleLogPrefix, ...message ); } -/** - * Logs a warning. - * - * @since 0.3.0 - * - * @param {...*} message - */ -function warn( ...message ) { - // eslint-disable-next-line no-console - console.warn( consoleLogPrefix, ...message ); -} - /** * Initializes extension. *