Most JS loaders do this by entering the <script> in the DOM and binding its onload to your provided function.
yepnope uses the same approach, and you may just notice that from its source code . The injectJs function creates a DOM element using doc.createElement , sets src and other necessary attributes using setAttribute , associates the onreadystatechange and onload with the provided callback, and finally inserts the element into the document.
source share