braintree / braintree-web-drop-in

Braintree Drop-in for the web
MIT License
200 stars 126 forks source link

How to speed up Drop-in script #735

Open wasshuber opened 3 years ago

wasshuber commented 3 years ago

General information

Issue description

Processing of dropin.min.js takes about 2 seconds. Is there anyway to speed this up? I am calling the script at the very top after <head> like this: <script src="https://js.braintreegateway.com/web/dropin/1.28.0/js/dropin.min.js"></script>

Here is an example javascript code how I am using the drop-in. Anything I am doing wrong? Any suggestions to make it faster?

var subm_button = document.querySelector("#submit-button");
braintree.dropin.create({
  authorization: <KEY>,
  container: "#dropin-container",
  locale: "en_US",
  dataCollector: {},
  card: {
    overrides: {
      fields: {
        postalCode: {
          prefill: "02143"
        }
      }
    }
  },
  //vaultManager allows customers to delete their past used and stored credit cards
  vaultManager: true,
  paypal: {
    flow: "checkout",
    amount: "4.50",
    currency: "USD",
    //flow: "vault",
    buttonStyle: {
      color: "gold",
      shape: "rect",
      size: "responsive",
      label: "paypal",
      tagline: "false"
    }}
  //venmo: {}
}, function (createErr, instance) {
  subm_button.addEventListener("click", function (event) {
    //need to find value of radio button via querySelector otherwise it does not work on IE
    var radio_value = document.forms["checkout_payment"].querySelector('[name="payment"]:checked').value;
    if (radio_value == "braintree_payments") {
        event.preventDefault();
        instance.requestPaymentMethod(function (err, payload) {
            document.getElementById("BTdevicedata").value = payload.deviceData;
            document.getElementById("BTnonce").value = payload.nonce;
            document.forms["checkout_payment"].submit();
        });
    }
  });
});
crookedneighbor commented 3 years ago

There's nothing you can do right now, but rendering speed is one of our chief concerns for the next major version of Drop-in. I'll leave this issue open and mark it with the v2 label.

wasshuber commented 3 years ago

That is great to hear that rendering speed is an area you are focusing on for future releases. I am looking forward to it. If you need a site to test it on I am more than happy to do that on my life production website.