Using external javascript files in a .js file

Javascript doesn’t have any implicit “include this other file” mechanisms, like css’s @include. You just have to list your globals file before the logic file in the tags:

 <script type="text/javascript" src="https://stackoverflow.com/questions/2579883/globals.js" />
 <script type="text/javascript" src="logic.js" />

If guaranteeing that the globals are available before anything in the logic file fires up, you can do a slow polling loop to see if some particular variable is available before calling an init() or whatever function.

Leave a Comment