0

I'm trying to call a library script (locomotive) in vanilla JS without Jquery, after the whole page and its assets had loaded. I've already tried with something like this:

<body onload="script('./js/lib/locomotive.min.js')";>

But it isn't working, the whole page loads but the script is never called. I've also tried placing the defer after the scripts call, but still nothing. I saw this other solution in other comments:

document.addEventListener("DOMContentLoaded", function(){

    //....
    //  **But I don't know how to call in here the 
      *./js/lib/locomotive.min.js*** 

});

Is there something else I could try?

aynber
  • 22,380
  • 8
  • 50
  • 63
  • You could dynamically load the file on the `DOMContentLoaded` event: https://stackoverflow.com/questions/14521108/dynamically-load-js-inside-js – Ian H. Jul 27 '22 at 14:23

1 Answers1

0

Your answer may be how to dynamic import script in js. the base way is that insert a tag by dom api.

e.g.

const script = document.createElement('script')
script.src = './js/lib/locomotive.min.js'
document.head.appendChild(script)

if you wanna more functions, plz try loadjs

X-Ray
  • 59
  • 6