• Hi, how are you?

    I’m trying to enqueue all my js, to see if that improve my load speed.

    When I try to get each handler with these lines in the functions.php (I don’t kwno another way):

    function head_scripts_handle() {
    global $wp_scripts;
    foreach( $wp_scripts->queue as $handle ) :
    echo $handle,’ ‘;
    endforeach;
    }
    add_action( ‘wp_print_scripts’, ‘head_scripts_handle’ );

    I only get some handlers, about 23, and if I go to the source code of my site I see 32 js.

    There is a way to get all the handlers? And for example:

    JS Handle
    script.js script handle

    So, I will have the script X belong to the handler X (there are a few scripts that I can’t identify the handler).

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s no easy way. The scripts queue only contains scripts that were properly enqueued. Unfortunately, it’s quite common for coders to not enqueue, but echo out their link tags from some action hook like ‘wp_head’ or ‘wp_print_scripts’. You may be able to locate script that does this by finding their callbacks in global $wp_filter (which has action hooks too). Then grep for the callback in your installation to locate the function declaration. Once it is known how the script link is output, you can decide how to proceed, such as removing the offending hook and properly enqueuing the script.

    Some script links are not even output through hooks, they are hardcoded right on the template or some included file. Try grepping for the linked file name to locate such code. Unfortunately, grep is not infallible. If the search term is dynamically constructed, grep cannot locate it. Your only recourse then is a tedious process of elimination. Deactivate plugins one by one, finding the plugin responsible for a link by the fact the link disappears when the plugin is deactivated.

Viewing 1 replies (of 1 total)
  • The topic ‘Know JS handlers.’ is closed to new replies.