Page Speed Insights 为 Google Recaptcha 删除未使用的 JavaScript [英] Page Speed Insights Remove unused JavaScript for Google Recaptcha

查看:46
本文介绍了Page Speed Insights 为 Google Recaptcha 删除未使用的 JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Google Page Speed Insights 上得分很高的网站,但它显示了一个性能问题,显示该文件的删除未使用的 JavaScript":

I have a site that scores well on Google Page Speed Insights, but it shows a performance issue that says "Remove unused JavaScript" for this file:

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

但是,我尝试删除我的 Invisible Captcha 插件,并将这行代码添加到 functions.php:

However, I have tried removing my Invisible Captcha plugin, and also adding this line of code to functions.php:

add_action('wp_print_scripts', function () {
    if ( is_home() ){
        wp_dequeue_script( 'google-recaptcha' );
        wp_dequeue_script( 'google-invisible-recaptcha' );
    }
});

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

But I still get the error. Is there anything I can do to remove this script from loading on my home page? My site is using the latest version of Wordpress.

推荐答案

以下对我有用:

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

这篇关于Page Speed Insights 为 Google Recaptcha 删除未使用的 JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆