【问题标题】:Page Speed Insights Remove unused JavaScript for Google RecaptchaPage Speed Insights 为 Google Recaptcha 删除未使用的 JavaScript
【发布时间】:2021-04-19 15:49:29
【问题描述】:

我有一个网站在 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


【解决方案1】:

以下对我有用:

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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-13
    • 1970-01-01
    • 2017-09-01
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    相关资源
    最近更新 更多