Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.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
Javascript 如何在wordpress中异步将jQuery排队?_Javascript_Php_Wordpress - Fatal编程技术网

Javascript 如何在wordpress中异步将jQuery排队?

Javascript 如何在wordpress中异步将jQuery排队?,javascript,php,wordpress,Javascript,Php,Wordpress,我的主题使用Wordpress的捆绑jQuery,我想异步加载它。(是的,PageSpeed Insights…这有一个钩子。您可以按如下方式使用它 add_filter( 'script_loader_tag', 'add_async_to_script', 10, 3 ); function add_async_to_script( $tag, $handle, $src ) { //You can use this to make all async $tag =

我的主题使用Wordpress的捆绑jQuery,我想异步加载它。(是的,PageSpeed Insights…

这有一个钩子。您可以按如下方式使用它

add_filter( 'script_loader_tag', 'add_async_to_script', 10, 3 );
 
function add_async_to_script( $tag, $handle, $src ) {

    //You can use this to make all async

    $tag = str_replace( ' src', ' async src', $tag );

    // You can use this to make it work as below for a specific script

    if ( 'dropbox.js' === $handle ) {
        $tag = '<script async type="text/javascript" src="' . esc_url( $src ) . '"></script>';
    }
 
    return $tag;
}
add_过滤器('script_loader_tag','add_async_to_script',10,3);
函数add\u async\u到脚本($tag、$handle、$src){
//您可以使用此选项使所有对象都异步
$tag=str_replace('src','async src',$tag);
//对于特定脚本,您可以使用此命令使其如下所示工作
if('dropbox.js'==$handle){
$tag='';
}
返回$tag;
}

根据网站的功能,异步延迟或加载jquery可能会影响页面的加载方式,甚至中断功能。它还不如运行顺利

但是为了给你一个正确的答案,我必须建议你不要这样做。

如果你想继续尝试,这里有一些参考资料


谢谢,它很有效!不幸的是,如果我异步加载脚本,PageSpeed不会给我更多分数。:/我尽量推迟。