Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable zxcvbn.min.js in wordpress and woocommerce

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

like image 562
egmontt Avatar asked Aug 19 '17 08:08

egmontt


4 Answers

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).

like image 108
Jasom Dotnet Avatar answered Nov 12 '22 05:11

Jasom Dotnet


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');
}
like image 6
Andrey Ptashinskiy Avatar answered Nov 12 '22 05:11

Andrey Ptashinskiy


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');
like image 1
MartinG Avatar answered Nov 12 '22 06:11

MartinG


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 completely 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

like image 1
TitanWP Avatar answered Nov 12 '22 05:11

TitanWP