Can stripe.js be loaded in non-blocking fashion?

不羁的心 提交于 2020-01-12 13:48:10

问题


Can stripe.js be deferred and used with some ready - callback that i can't find in the docs?

This is what i wanna do:

<script src="https://js.stripe.com/v2/" async></script>

And then in my app:

function stripeReadyHandler () {
  //do stuff
}

回答1:


Turns out, there's a standards compliant way to do this:

<script src="https://js.stripe.com/v2/" async onload="stripeReadyHandler()"></script>

and then:

function stripeReadyHandler () {
  //this will definitely do stuff ( if you're above IE9 of course
}



回答2:


Or, with JavaScript:

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://js.stripe.com/v2/';
document.body.appendChild(script);
script.onload = function() {
  Stripe.setPublishableKey(publishableKey);
  // do stuff
};


来源:https://stackoverflow.com/questions/25715092/can-stripe-js-be-loaded-in-non-blocking-fashion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!