最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - disable zxcvbn.min.js in wordpress and woocommerce - Stack Overflow

programmeradmin6浏览0评论

As you know zxcvbn.min.js is around 400kb and loaded by default in wordpress websites , I want to know how I can prevent this JavaScript library to load As I don't want password length checking in my site

As you know zxcvbn.min.js is around 400kb and loaded by default in wordpress websites , I want to know how I can prevent this JavaScript library to load As I don't want password length checking in my site

Share Improve this question edited Aug 19, 2017 at 8:58 Osama AbuSitta 4,0664 gold badges37 silver badges54 bronze badges asked Aug 19, 2017 at 8:41 egmonttegmontt 671 gold badge2 silver badges10 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 7

Add the following to your theme's function.php or to a custom plugin:

//disable zxcvbn.min.js in wordpress
add_action('wp_print_scripts', 'remove_password_strength_meter');
function remove_password_strength_meter() {
    // Deregister script about password strenght meter
    wp_dequeue_script('zxcvbn-async');
    wp_deregister_script('zxcvbn-async');
}

This code in my theme function.php worked for me:

/**
 * Deregister scripts
 */
function deregister_or_dequeue_scripts() {
    wp_dequeue_script('wc-password-strength-meter');
}

add_action('wp_print_scripts', 'deregister_or_dequeue_scripts', 20);

It will remove wc-password-strength-meter javascript and all its dependences (including zxcvbn.min.js).

The previous answer didn't worked for me, maybe because I usewp_enqueue_scripts so here is my setup that got me rid of the wc-password-strength-meter :

function my_add_frontend_scripts() {
    // Deregister script about password strenght meter ~ 800kb
    wp_dequeue_script('wc-password-strength-meter');
    wp_deregister_script('wc-password-strength-meter');

    wp_register_script('custom-script', get_stylesheet_directory_uri().'/custom-script.js', array('jquery'), 1, false );
    wp_enqueue_script('custom-script');
    }

add_action('wp_enqueue_scripts', 'my_add_frontend_scripts');

So far the wp_enqueue_scripts code is the only solution that actually succeeded in removing the password strength meter files from being loaded. Total page size decreased by about 400KB which was awesome. (841KB to 439KB)

The problem is adding that code to my functions.php actually slowed down the load time... It caused a 404 error and WebPageTest shows TTFB for that file itself was 900ms after multiple trials.

On one hand I'm encouraged that something actually blocked the Javascript from being loaded and the total site size being cut in half. On the other hand the code you supplied slowed my site down (from 404 error and TTFB 900ms)

I just can't believe Wordpress doesn't have a built in option to pletely disable this in the admin dashboard. I'm not talking about blocking PW Java from loading on some pages, im saying COMPLETELY GONE.

If you are the sole user/admin/owner of your website (an don't allow anyone to register) and aren't dumb enough to make your password "1234" there is absolutely no point in having a pw strength meter. It results a big page size and slower load time. My site is 841KB and 400KB is the stupid pw strength meter. So frustrating!

There are literally thousands of people searching for this solution.

-cal

404 error & TTFB

发布评论

评论列表(0)

  1. 暂无评论