0

I want to be sure that my scripts are being loaded before I call a function.

This code is written inline on the page, it is not being loaded by application.js, sometimes the scripts are loaded correctly but not always.

<script>
$(document).on('turbolinks:load', function() {
  $.when(
  // Required libs to token and fraud detection
  $.getScript("https://openpay.s3.amazonaws.com/openpay.v1.min.js"),
  $.getScript("https://openpay.s3.amazonaws.com/openpay-data.v1.min.js"),
  $.Deferred(function(deferred){
      $(deferred.resolve);
  })
).done(function(){
  OpenPay.setId('123');
  ... more code ...
});
</script>

I'm getting:

enter image description here

How can I do that? I'm using rails 5

3
  • Have you added your application.js to your application.html.erb file or whatever it's name is which contains your meta tags, <!DOCTYPE html> stuff, and header (<head>)? Commented Jul 2, 2018 at 19:09
  • Yes, but this script is used "inline" to say it in some way. is in the same html that uses it. the problem is that sometimes it loads and sometimes it does not, I think it's because the code inside the function sometimes loads before the library openpay.s3.amazonaws.com/openpay.v1.min.js and openpay.s3.amazonaws.com/openpay-data.v1.min.js and thats why return ReferenceError, but I do not know how to make me load the libs before the function and that this is always effective so that I do not return the ReferenceError Commented Jul 2, 2018 at 21:06
  • I found a related stackoverflow post might be useful. stackoverflow.com/questions/31011528/… Commented Jul 3, 2018 at 13:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.