I am using jQuery to dynamically add script tags in the body tab of a web page. I got something like:
function addJS(url) {
$("body").append('<script type="text/javascript" src='+url+'></script>');
}
I add a few scripts this way and try to use them right after. EG:
lib.js
function core() {...}
alert("I'am here !");
init.js
addJS("lib.js");
c = new core();
test.html
<html>
<head>
<title>test</title>
<script type="text/javascript" src="init.js"></script>
</head>
<body>
Hello
</body>
</html>
Downloading test.html pops up "I'm here" and then ends with the error "kernel is not defined". Of course, merging both JS files will allow them to work perfectly.
I just don't get it o_O.
EDIT
I simplified this example, but Jeff's answer made me realize that it was a mistake. So here are some details:
init.js is not in the test.html header when it reloads because I am inserting it with code expressed on a bookmarklet.
So, the real execution process is as follows:
reload test.html > > jquery init.js > lib.js
.
2
( :-)), . ?