谷歌页面速度分析:删除未使用的JavaScript以适配reCAPTCHA。

6

我有一个网站在Google页面速度洞察中得分很高,但它显示了一个性能问题,指出这个文件需要“删除未使用的JavaScript”:

https://www.gstatic.com/recaptcha/releases/2diXFiiA9NsPIBTU15LG6xPf/recaptcha__en.js

然而,我已经尝试删除我的Invisible Captcha插件,并且还在functions.php中添加了这行代码:
add_action('wp_print_scripts', function () {
    if ( is_home() ){
        wp_dequeue_script( 'google-recaptcha' );
        wp_dequeue_script( 'google-invisible-recaptcha' );
    }
});

但我仍然收到错误提示。有什么办法可以让这个脚本不加载在我的主页上吗?我的网站正在使用最新版本的WordPress。


我也很好奇这个问题。我曾经遇到过类似的性能问题。 - jackhowa
1个回答

0

以下方法对我有效:

add_action( 'wp_enqueue_scripts', 'mytheme_deregister_scripts' );
function mytheme_deregister_scripts() {
  if( is_home() || is_front_page() ) :
    wp_deregister_script('google-invisible-recaptcha');
  endif;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接