using JS to place – TempestDev Jul 21 '20 at 17:13

  • Any requirements should be spelled out in the question, not the comments. Please [edit] your question to include any information that people should know. Note that `src="www.example.com/sandbox"` will likely result in an attempt to get the script from `http://baseURL/www.example.com/sandbox`, which may more may not be what you want. – Heretic Monkey Jul 21 '20 at 17:18
  • Yeah i know the one that is normally in there is an api front end with the api key – TempestDev Jul 21 '20 at 17:22
  • This is jquery code, thus you have to import jquery as well. – NVRM Jul 22 '20 at 16:40
  • I have jquery imported – TempestDev Jul 22 '20 at 19:09
  • 1 Answers1

    0

    There is many ways, but our browsers have now this capabilities built-in!

    Dynamic Imports

    Example using a lib suncalc.js, the server must have CORS enabled to works this way!

    Example, getting a lib from a CDN, after DOM load, directly available in the current context:

    (async () => {
     // Get and import the lib
     await import('https://cdnjs.cloudflare.com/ajax/libs/suncalc/1.8.0/suncalc.min.js')
     .then(function(){
       // Lib ready to use
       let times = SunCalc.getTimes(new Date(), 51.5,-0.1);
       console.log("Golden Hour today in London: " + times.goldenHour.getHours() + ':' + times.sunrise.getMinutes() + ". Take your pics!")
      })
    })()

    From

    NVRM
    • 11,480
    • 1
    • 88
    • 87
    • This requires the code in the JavaScript file to support being loaded as a module. Also, since you've already used almost exactly the same answer elsewhere, you should be closing the question as a duplicate, not pasting the same answer across multiple questions. – Heretic Monkey Jul 21 '20 at 17:22
    • Yes, Modern browsers, https://caniuse.com/#feat=es6-module-dynamic-import – NVRM Jul 21 '20 at 17:25
    • yeah this didnt exactly help, just importing a external script after a bit of time. thanks Heretic Monkey for trying to point that out to probably a ?bot? ive edited my question and hopefully its better to understand. – TempestDev Jul 22 '20 at 15:01