Page Speed Insights 为 Google Recaptcha 删除未使用的 JavaScript

Ale*_*las 6 wordpress recaptcha pagespeed lighthouse invisible-recaptcha

我有一个在 Google Page Speed Insights 上得分很高的网站,但它显示了一个性能问题,显示此文件的“删除未使用的 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' );
    }
});
Run Code Online (Sandbox Code Playgroud)

但我仍然收到错误。我可以做些什么来从主页上的加载中删除此脚本?我的网站使用的是最新版本的 Wordpress。

Vai*_*nor 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;
}
Run Code Online (Sandbox Code Playgroud)