Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 我应该使用wp_enqueue_script()将外部脚本排队吗?_Wordpress - Fatal编程技术网

Wordpress 我应该使用wp_enqueue_script()将外部脚本排队吗?

Wordpress 我应该使用wp_enqueue_script()将外部脚本排队吗?,wordpress,Wordpress,使用该函数将外部脚本排队是否正确? 它可以工作,但不会减慢网站的开放速度吗 wp_register_script( 'google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=true', null, null, true ); wp_register_script( 'jsapi', 'https://www.google.com/jsapi', null, null, true ); wp_register_script( 'b

使用该函数将外部脚本排队是否正确? 它可以工作,但不会减慢网站的开放速度吗

wp_register_script( 'google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=true', null, null, true );
wp_register_script( 'jsapi', 'https://www.google.com/jsapi', null, null, true );
wp_register_script( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', null, null, true );
wp_register_script( 'unveil', get_template_directory_uri() . '/new-js/jquery.unveil.min.js', null, null, true );

不,这不会减慢网站的速度(至少不足以成为不使用它的理由)。这是在WordPress中将任何类型的脚本排队的正确方法。此函数所做的只是将适当的
标记(带依赖项)添加到HTML

但是,由于某些原因,您的代码中没有包含依赖项。例如,引导需要jQuery,因此您应该将其包含在函数中:

wp_enqueue_script( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array('jquery'), '3.3.5', true );

如上文所示,您还应该考虑使用<代码> > WpReistSysScript()/<代码>,因为它将为您节省一个步骤。我这样问是因为当外部脚本使整个页面变慢(阻止其他脚本)时,我遇到了一个问题。我对facebook、地图和bootstrap有问题。有简单的解决办法吗?