Jump to content

"Include" JS files into other JS files


shadowayex

Recommended Posts

I was wondering about a way to "include" other JS files into a JS file.My aim is to have a few files with collections of related, useful functions, and then apply those functions in different projects, but make it so only the file containing the project has to be linked to the HTML file via script tag.I found one solution that was of the sort:

document.write("<script type='text/javascript' src='myFunctions.js'></script>");

But I'm not sure if that is the best solution or not.

Link to comment
Share on other sites

That is the general idea - document.write() will clear the screen, though, so if you want to load another JavaScript file after the page loads, then it is better to create the element another way, e.g. by writing to an elements innerHTML, or by using the DOM.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...