I have a script foo.js that is included in <head>. Inside body I have an inline script. Inside it, I want to add to the document another script for bar.js that will be loaded and evaluated before the inline script.
<html> <head> <script src="foo.js" type="text/javascript"/> </head> <body> <script type="text/javascript"> bar() </script> </body> </html> In foo.js I want to add a script pointing to bar.js
bar.js:
function bar() { alert('hi'); } What should be the code of foo.js?
NOTE: I know I can use onload in this trivial example. But in my real case, bar.js contains a function that is called several times and I want to be able to inline these calls in the right sections of the page (for code locality)