Victor Ferreira Victor Ferreira - 8 months ago 47
Javascript Question

Programatically loads Javascript file and load code when it's finished

I'm working in a React project that uses jQuery and I need to import a jQuery library to it.

Basically, what I need right now is a way to load a javascript in my project dynamically and when it finishes loading I need to run a javascript code.

something like this:

//run this code when myscript has finished loading


$.getScript does what you want.

$(function() {
    $.getScript('myscript.js', function() {
        // run when myscript has finished loading