虽然将所有JS文件合并到一个JavaScript中并将其排队以减少HTTP请求是一种更好的做法,但也可以将它们单独排队。因此,您可以注册脚本(不是必需的),然后将其排队。
只需在注册所有脚本后将其排队,如:
// Template ABC
if ( is_page_template( array(\'template-1.php\',\'template-2.php\'))):
wp_register_script( \'Name of JS File\', \'https://url.js\' );
wp_register_script( \'Name of NEW JS File 1\', \'https://url-new-1.js\' );
wp_register_script( \'Name of NEW JS File 2\', \'https://url-new-2.js\' );
wp_enqueue_script(\'Name of JS File\');
wp_enqueue_script(\'Name of JS File 1\');
wp_enqueue_script(\'Name of JS File 2\');
endif;
或直接将其全部排队:
// Template ABC
if ( is_page_template( array(\'template-1.php\',\'template-2.php\'))):
wp_enqueue_script( \'Name of JS File\', \'https://url.js\' );
wp_enqueue_script( \'Name of NEW JS File 1\', \'https://url-new-1.js\' );
wp_enqueue_script( \'Name of NEW JS File 2\', \'https://url-new-2.js\' );
endif;