• Resolved preetindersodhi

    (@preetindersodhi)


    Please convert the javascript code to vanilla javascript.

    jQuery is very bloated and affects the performance of the website.

    Plain javascript version:

    var wpa_field_name, wpa_unique_id, wpa_add_test, wpa_hidden_field;

    document.addEventListener("DOMContentLoaded", function () {
    wpa_field_name = wpa_field_info.wpa_field_name;
    wpa_unique_id = wpa_field_info.wpa_field_value;
    wpa_add_test = wpa_field_info.wpa_add_test;

    wpa_hidden_field = "<div id='altEmail_container' class='altEmail_container'><label for='alt_s'>Alternative:</label><input type='text' id='alt_s' name='alt_s' ></div><span class='wpa_hidden_field' style='display:none;height:0;width:0;'><label>WPA <input type='text' name='" + wpa_field_name + "' value='" + wpa_unique_id + "' /></label></span>";

    wpa_add_honeypot_field();

    if (typeof wpae_add_honeypot_field === 'function') {
    wpae_add_honeypot_field();
    }

    if (wpa_add_test === 'yes') {
    wpa_add_test_block();
    }
    });

    function wpa_act_as_spam() {
    var button = document.querySelector('span.wpa-button');
    var actiontype = button.getAttribute('data-actiontype');

    if (actiontype === 'remove') {
    wpa_remove_honeypot_field();
    button.setAttribute('data-actiontype', 'add');
    button.innerHTML = 'Acting as Spam Bot';
    } else {
    wpa_add_honeypot_field();
    button.setAttribute('data-actiontype', 'remove');
    button.innerHTML = 'Act as Spam Bot';
    }
    }

    function wpa_add_honeypot_field() {
    var selectors = [
    'form.wpcf7-form, .wpcf7 form',
    'form.wpforms-form',
    '.gform_wrapper form',
    '.frm_forms form',
    '.caldera-grid form',
    '.wp-block-toolset-cred-form form',
    'form.cred-user-form',
    'form.cred-form',
    'form.et_pb_contact_form',
    'form.fb_form',
    'form.elementor-form',
    'form.form-contribution',
    'form.cart',
    'form#learn-press-checkout-form',
    'form.wpa_form',
    '.wpa_form form',
    'form.spectra-pro-login-form',
    'form#loginform',
    'form#edd_login_form',
    'form.uwp-login-form',
    '.et_pb_login_form form',
    'form.eael-login-form',
    'form#commentform',
    'form.ast-commentform',
    'form#fl-comment-form',
    'form.comment-form',
    '.review-form form',
    'form#edd-reviews-form',
    '.bbp-topic-form form',
    '.bbp-reply-form form'
    ];

    document.querySelectorAll(selectors.join(', ')).forEach(function (form) {
    form.insertAdjacentHTML('beforeend', wpa_hidden_field);
    });

    document.querySelectorAll('form.frm-fluent-form, .ff_conv_app').forEach(function (form) {
    form.insertAdjacentHTML('beforeend', wpa_hidden_field);
    });

    if (typeof fluent_forms_global_var_1 !== 'undefined') {
    fluent_forms_global_var_1.extra_inputs[wpa_field_name] = wpa_unique_id;
    fluent_forms_global_var_1.extra_inputs['alt_s'] = '';
    }

    document.querySelectorAll('input.wpa_initiator').forEach(function (input) {
    var form = input.closest('form');
    if (form && form.querySelector('.wpa_hidden_field') === null) {
    input.insertAdjacentHTML('afterend', wpa_hidden_field);
    }
    });
    }

    function wpa_add_test_block() {
    var testBlock = "<div class='wpa-test-msg'><strong>WP Armour ( Only visible to site administrators. Not visible to other users. )</strong><br />This form has a honeypot trap enabled. If you want to act as spam bot for testing purposes, please click the button below.<br/><span class='wpa-button' onclick='wpa_act_as_spam()' data-actiontype='remove'>Act as Spam Bot</span></div>";
    document.querySelectorAll('.wpa-test-msg').forEach(function (el) { el.remove(); });
    document.querySelectorAll('span.wpa_hidden_field').forEach(function (el) {
    el.insertAdjacentHTML('afterend', testBlock);
    });
    }

    function wpa_remove_honeypot_field() {
    document.querySelectorAll('.wpa_hidden_field, #altEmail_container, .altEmail_container').forEach(function (el) {
    el.remove();
    });

    if (typeof fluent_forms_global_var_1 !== 'undefined') {
    delete fluent_forms_global_var_1.extra_inputs[wpa_field_name];
    delete fluent_forms_global_var_1.extra_inputs['alt_s'];
    }
    }
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Dnesscarkey

    (@dnesscarkey)

    Hi Preetinder,

    Thank you for your feedback! We understand your concern about jQuery and are planning to transition to JavaScript. However, since jQuery comes bundled with WordPress by default, we initially chose to go with it for compatibility reasons.

    With over 200K active installations, making major changes requires careful implementation to avoid breaking existing setups, especially with caching plugins in use. We want to ensure a smooth transition without disrupting functionality.

    That said, we truly appreciate your input and will keep it in mind as we work towards optimizing the plugin.

    Thanks

    Thread Starter preetindersodhi

    (@preetindersodhi)

    Thank you. WordPress itself does not load jQuery on front-end by default unless it is added by theme or any plugin.

    I avoid plugins that add a lot of code, but I love your plugin. I’ve tried many different anti-spam plugins. I’m using it on around 50 sites and I want to add it to 200 more, but jQuery is a problem.

    Plain javascript won’t require anything else, there’s no reason why it would break the site.

    Caching could break site, if it unloads jQuery but still loads the old jQuery based code, but why would that happen in the first place? JS file will have a new version attached to it, so server would serve new code, not old.

    It’s difficult to achieve core web vitals if you have jQuery on your site. Please switch to plain javascript code. Thanks for creating such an awesome plugin!

    Plugin Author Dnesscarkey

    (@dnesscarkey)

    Hi Preetinder,

    Thank you for your detailed feedback and for supporting our plugin! We understand the concerns regarding jQuery and its impact on core web vitals. We will definitely look into the possibility of switching to plain JavaScript in future updates.

    Appreciate your support and insights!

    Best,

    Thread Starter preetindersodhi

    (@preetindersodhi)

    Any update regarding this? It’s been over a month. Because of your plugin, I’m unable to pass the core web vitals test, as your plugin loads jQuery.

    Kindly convert the Javascript code so it does not require jQuery. Unnecessary bloat, awful for performance. Please make the plugin lightweight.

    Thread Starter preetindersodhi

    (@preetindersodhi)

    Any update regarding removing jQuery dependency? If you’re not gonna do it, let me know. I currently use your plugin on over 100+ sites, I’d rather develop my own, if you won’t remove the bloated jQuery.

    Plugin Author Dnesscarkey

    (@dnesscarkey)

    Hi @preetindersodhi,

    While talking with others users i had mixed reactions. So what i was thinking was to use Jquery as option. Will add an option (may be called Don’t use Jquery ) in Setting page where you can disable it and it will use pure JS.

    Let me know if it works. If it is fine, i will send this option in new update.

    Thread Starter preetindersodhi

    (@preetindersodhi)

    That’ll work. Talk to those who want faster page speed, they would appreciate you for reducing code.

    i can not understand why you still want to stick to jquery instead of dropping it entirely!? why providing an option to still support jquery? for what? the code is relatively simple and does not need jquery at all. i also provided vanilla js code done by chatgpt.

    • This reply was modified 6 months, 3 weeks ago by nicmare.
    Plugin Support Dinesh Karki

    (@dcsupport)

    It’s more about providing deprecation support. In the past, we faced issues when rolling out major changes, and since we have a large user base, we didn’t want to break existing setups. This approach also helps us with testing and ensures that everything works smoothly.

    In future it’ll be best to phase out jQuery, because in case of your plugin, using vanilla javascript means less code, faster speed, no dependencies.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Please remove jQuery dependency.’ is closed to new replies.