Created
April 3, 2024 18:47
-
-
Save westonruter/022f630d06b50de486f3bf569a5e3803 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery( function ( $ ) { | |
const blockMainThread = function ( ms ) { | |
console.info( `blocking for ${ms} ms.` ); | |
const startTime = performance.now(); | |
while ( performance.now() - startTime < ms ) { | |
continue; | |
} | |
}; | |
$( () => { | |
blockMainThread( 1000 ); | |
$( window ).on( 'load', () => { | |
blockMainThread( 1000 ); | |
} ); | |
$( document.body ).on( 'click', () => { | |
blockMainThread( 1000 ); | |
} ); | |
} ); | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Try jQuery Callback | |
* Description: Testing if Lighthouse is attributing slow code to jQuery or the underlying plugin code that is using jQuery. | |
*/ | |
add_action( | |
'wp_enqueue_scripts', | |
static function () { | |
wp_enqueue_script( 'try-jquery-callback', plugin_dir_url( __FILE__ ) . '/script.js', array( 'jquery' ), filemtime( __DIR__ . '/script.js' ) ); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When analyzing page load with Lighthouse, unfortunately it is blaming
jquery.js
for the TBT and notscript.js
as it should be: