dqwcdqs358367 2018-09-13 15:58
浏览 68

对于WordPress中的load-scripts.php,PageSpeed问题“删除渲染阻止JavaScript:”

We are currently trying to improve our PageSpeed scores but still stuck at 70. One of the remaining issues is below:

Remove render-blocking JavaScript: https://www.example.com/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core&ver=4.9.8

This is a WordPress-generated source, but I tried hacking it and added "async" to the script reference but it breaks the site, returning JS errors. Is there any way we can fix this PageSpeed "issue"? Or is this something we should accept as a technical limitation?

  • 写回答

1条回答 默认 最新

  • duanmu6752 2018-09-13 21:40
    关注

    You'll probably never get a 100/100 score on PageSpeed Insight. You could try adding this function to defer or asynch script files:

    // Defer load scripts
    function defer_scripts( $tag, $handle, $src ) {
    
    // The handles of the enqueued scripts you want to defer
    $defer_scripts = array( 
        'NAME_OF_SCRIPT',
        'ANOTHER_SCRIPT',
    );
    
    if ( in_array( $handle, $defer_scripts ) ) {
        return '<script src="' . $src . '" defer="defer" type="text/javascript"></script>' . "
    ";
    }
    
    return $tag;
    } 
    
    add_filter( 'script_loader_tag', 'defer_scripts', 10, 3 );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题