Reactive - Loading and Using external javascript library (from URL)

Hello fellow developers,


As you can read in the title I am trying to use an external library from an URL which I cannot import. We also have some variable that we need to assign to make this work. 

I know that in traditional this is pretty easy using an expression, and I tried it and its working. 

Traditional solution in an expression:

<script type='text/javascript'>
    var width="100%";         
    var height="600";         // height in pixels
    var latitude="36.00";     // center latitude (decimal degrees)
    var longitude="-5.40";    // center longitude (decimal degrees)
    var zoom="15";             // initial zoom (between 3 and 18)
</script>
<script type="text/javascript" src="https://www.vesselfinder.com/aismap.js"></script>

Solution in JSFiddle

JSFiddle - Code Playground


Problem

 
But now that we are moving to reactive I am having some issues to make this script work. I already did some investigation and tried some solutions and couldn't make any work. Or it is just writing me the script on a tag but not loading it, or I am having some errors like: "VM1175 aismap.js:44 Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened." when I try to run it.


For a simple test I just created a screen, and in the OnInitialize I added this


Also tried using the InjectHTML webblock but without success:



I also already tried using both inside a SPAN element, but without success also. Am I missing something here? Is it normal that in reactive such a trivial developer daily requirement is that hard to implement? 



I really appreciate you guys reading this, I can provide any info that you might need just ask for it! Any suggestions are welcome, because I really need to make this work!

Thanks a lot once again,

VC

Hello @Vincent Colpa,

The recommended practice in Reactive web apps is to import/ create the external javascript library under the 'Scripts' folder for further use as described in this article.

The above approach has been debated in the forums for e.g in this thread where some alternate options have been suggested. I have not tried these alternatives but figured it may pique your interest.

Regards,

AJ

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.