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

问题描述 投票:0回答:2

我有一个网站在 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' );
    }
});

但我仍然得到错误。我可以做些什么来从我的主页上加载这个脚本吗?我的网站使用的是最新版本的 Wordpress。

wordpress recaptcha pagespeed lighthouse invisible-recaptcha
2个回答
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;
}

0
投票

我确实尝试过这个,但它不起作用...... 我也尝试了其他所有方法 - 似乎没有任何效果 :(>.... 帮助? 有什么建议么? What i experience in many websites tried - all the same.

© www.soinside.com 2019 - 2024. All rights reserved.