Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
}
like image 933
Daniel Birowsky Popeski Avatar asked Sep 07 '14 21:09

Daniel Birowsky Popeski


2 Answers

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
}
like image 111
Daniel Birowsky Popeski Avatar answered Sep 19 '22 23:09

Daniel Birowsky Popeski


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
};
like image 29
stephen.hanson Avatar answered Sep 21 '22 23:09

stephen.hanson