xwp / site-performance-tracker

Allows you to detect and track site performance metrics
GNU General Public License v2.0
96 stars 15 forks source link

Delay the loading of the library loading #39

Closed mehigh closed 2 years ago

mehigh commented 3 years ago

It might me a case that requestIdleCallback is executed right away and the lighthouse is picking up the change of src attribute, maybe we should change this to window.addEventListener('load') or setTimeout and inside that use requestIdleCallback with some timeout option?

https://github.com/xwp/site-performance-tracker/blob/master/php/Plugin.php#L84

manuelRod commented 2 years ago

@mehigh I need some context here. Not sure what I'm looking at to improve. ( Also that file/line you link does not exist anymore)

You mean to wrap this into window.addEventListener('load') ? requestIdleCallback( function() { webVitalsAnalyticsScript = document.querySelector( 'script[data-src*="web-vitals-analytics.js"]' ); webVitalsAnalyticsScript.src = webVitalsAnalyticsScript.dataset.src; delete webVitalsAnalyticsScript.dataset.src; } );

mehigh commented 2 years ago

Hi Manuel. Yes, that's what this refers to https://xwp-co.atlassian.net/wiki/spaces/KB/pages/2596208641/Total+Blocking+Time+Steps Please use a similar approach to the delayed load example in this section here. Default to 5000 (ms) and allow overriding with a filter which would be added to the readme. Thank you!

manuelRod commented 2 years ago

P.R: https://github.com/xwp/site-performance-tracker/pull/58