Can I load a script and then make a variable pointing to that loaded script?

488 views Asked by At

Is there any way in javascript or react to load a script inside the index.html and then import that loaded script in another file?

index.html
  <body>
    <script
      type="text/javascript"
      src="http://localhost:3001/myService.js"
    ></script>
    <div id="root"></div>

  </body>


anyOtherComponent.js
import myService from "  ";

Any suggestions are welcome.

1

There are 1 answers

0
Jeff B On

In short, not really. Your best bet is to download the file in question.

Please refer to this answer as well:

ES6: import module from URL