Optimizing WordPress’s styles and scripts

Query Monitor will show you what is loaded or you can print them directly.

function print_wp_scripts_queue(){

    $scripts = wp_scripts();

    echo "<pre><h1>scripts</h1>";
    print_r ( $scripts->queue );


    echo "<h1>todo</h1>";
    print_r ( $scripts->to_do );

    echo "<h1>done</h1>";
    print_r ( $scripts->done );

    echo "<h1>registered</h1>";    
    print_r ( $scripts->registered );

    echo "</pre>";
    wp_die();
}

add_action( 'wp_head', 'print_wp_scripts_queue', PHP_INT_MAX );

wp_deregister_script removes a script from the register. Meaning you won’t be able to reference by a name later.

wp_dequeue_script will remove it from the queue so it won’t render, which is what you want. Just make sure you do it after it has been enqueued.

Some scripts loading are dependent on other scripts to be loaded. So if you dequeue jQuery then most things won’t load because that’s usually the safest file to wait for. Dependencies also help with making sure styles or scripts have been added so the following style or script can expect the resource to exist.