Sometimes when making a theme or plugin, you want to conditionally enqueue a script or style so that it does not load on pages where it is not used. This process is generally pretty straight forward, just add your enqueue functions inside of conditional statements like this:
add_action('wp_enqueue_scripts', 'add_script_function');
function add_script_function() {
if(condition one === true) {
wp_enqueue_script('script1', 'location/script1.js');
} else {
wp_enqueue_script('script2', 'location/script2.js');
}
}
You can now use this: https://developer.wordpress.org/reference/functions/wp_add_inline_script/
Good snippet. what your thinking about Speed demon
It is probably a good idea to use something like that if you are not going to optimize the site ‘by hand’, meaning individually optimized for the specific plugins and themes being used.