List Enqueued Scripts and Styles in the Page Source
Prints an HTML comment at the bottom of each page, visible to administrators, listing every script and stylesheet handle loaded and its source, to find what to optimize.
Opens WPIDE on
Code
add_action( 'wp_print_footer_scripts', function () {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$lines = array( 'Enqueued assets' );
foreach ( array( 'scripts' => wp_scripts(), 'styles' => wp_styles() ) as $type => $deps ) {
$lines[] = strtoupper( $type ) . ':';
foreach ( $deps->done as $handle ) {
$src = isset( $deps->registered[ $handle ] ) ? (string) $deps->registered[ $handle ]->src : '';
$lines[] = ' ' . $handle . ( $src ? ' => ' . $src : ' (inline/alias)' );
}
}
echo "\n<!--\n" . esc_html( str_replace( '--', '- -', implode( "\n", $lines ) ) ) . "\n-->\n";
}, 999 );
Notes
View the page source and look for "Enqueued assets" near the end.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.