This might work, I have not tested:
if (mylib.myfunction) {
mylib.myfunction();
}
else {
if (!document.getElementById("scriptTag") ) {
var jsElt = document.createElement("script");
jsElt.onload = function() { mylib.myfunction(); }
jsElt.setAttribute("id", "scriptTag"); }
jsElt.setAttribute("src", MYLIB_URL);
body.head.appendChild(jsElt);
}