Possible Duplicates: Include a JavaScript file in a JavaScript file How to include a JavaScript file in another JavaScript file?
What is the best way to import a JavaScript file, for example file.js
, in a JavaScript function()?
For example, what is the best way to replace the todo statement:
function doSomething() {
if (xy.doSomething == undefined) {
// TODO: load 'oldVersionPatch.js'
}
...
}
Possibly the best solution is to create script element and add it into the HTML page.
- Is it better to add/append it into head, or body (what will load when)?
- Is it better to use JavaScript or jQuery (what is more cross-browser compatible)?