filters - Unable to defer loading of jquery

I have two render blocking JS from wordpress core. jquery.js and jquery-migrate.min.js. Following this answer on WPSE I

I have two render blocking JS from wordpress core. jquery.js and jquery-migrate.min.js. Following this answer on WPSE I was able to add `defer="defer"' to the script tag that calls for jquery-migrate and bootstrap, but doing the same for 'jquery' does not add the defer property to the script tag that calls for jquery.js

  add_filter( 'script_loader_tag', function ( $tag, $handle ) {
    $handlesToDefer = array('jquery-migrate', 'bootstrap', 'jquery');

    if ( !in_array($handle, $handlesToDefer) )
        return $tag;

    return str_replace( ' src', ' defer="defer" src', $tag );
 }, 1, 2 );

I have two render blocking JS from wordpress core. jquery.js and jquery-migrate.min.js. Following this answer on WPSE I was able to add `defer="defer"' to the script tag that calls for jquery-migrate and bootstrap, but doing the same for 'jquery' does not add the defer property to the script tag that calls for jquery.js

  add_filter( 'script_loader_tag', function ( $tag, $handle ) {
    $handlesToDefer = array('jquery-migrate', 'bootstrap', 'jquery');

    if ( !in_array($handle, $handlesToDefer) )
        return $tag;

    return str_replace( ' src', ' defer="defer" src', $tag );
 }, 1, 2 );

Share Improve this question edited Sep 30, 2019 at 14:13 Chetan Vaghela 2,4084 gold badges10 silver badges16 bronze badges asked Sep 30, 2019 at 13:42 OctaviaLoOctaviaLo 1398 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
add_filter( 'script_loader_tag', function ( $tag, $handle ) {
$handlesToDefer = array('jquery-migrate', 'bootstrap', 'jquery-core');

if ( !in_array($handle, $handlesToDefer) )
    return $tag;

return str_replace( ' src', ' defer="defer" src', $tag );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745118208a4612257.html

相关推荐

  • filters - Unable to defer loading of jquery

    I have two render blocking JS from wordpress core. jquery.js and jquery-migrate.min.js. Following this answer on WPSE I

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信