Having said that there are various ways to add a script dynamically, the way to do this is by adding a <script> node to the body of the document when the DOM is ready, and then delete it if it takes a long time to load.
<html> <head> <title>bla</title> <script type="text/javascript"> function init(){ var max_time = 2000 </script> </head> <body>bla bla [...]</body> </html>
You can then add an instruction to reset the timeout at the end of the dynamically loaded script:
/* end of http://yoursite.net/script.js code */ clearTimout(g_timeout);
Note:
document.addEventListener does not work in IE if you want a cross-platform solution to use the Jquery $ (document) .ready method or look at the equivalent of a document without jQuery
source share