Is it possible to somehow connect one js file to another? something like:

include 'js_prev.js'; console.log('...'); 

1 answer 1

You can write such a function

 function include(url) { var script = document.createElement('script'); script.src = url; document.getElementsByTagName('head')[0].appendChild(script); } 

and use

 include('js_prev.js'); 

Another option is to use jQuery.getScript() . Good examples are in the native documentation .

You can also look towards RequireJS and CommonJS . But these are more costly methods, it will be necessary to reorganize all the scripts into a modular architecture. The implementation of the last one (CommonJS) is the basis of the modules.

In addition, native module support has been added to the new javascript standard (ECMAScript 6).