i didnt find a simple way of doing this either .. i studied your link but its beyond my programming skills .
i found one example of script loading on the MDN website
[{"id":"f6b104981899da0e","type":"ui_template","z":"5847b7aa62131d37","group":"cecf42695640eca4","name":"","order":0,"width":0,"height":0,"format":"<div id=\"vis\" style=\"height:500px\"></div>\n<script>\n\nlet nr = scope;\n\nfunction loadError(oError) {\n throw new URIError(\"The script \" + oError.target.src + \" didn't load correctly.\");\n}\n\nfunction affixScriptToHead(url, onloadFunction) {\n var newScript = document.createElement(\"script\");\n newScript.onerror = loadError;\n if (onloadFunction) { newScript.onload = onloadFunction; }\n document.head.appendChild(newScript);\n newScript.src = url;\n}\n\n// main code runs with this function\nfunction myJS() {\nnr.$watch('msg.vega', function(data) {\n const spec = data;\n console.log(\"Mesg received from NR\", spec)\n \n vegaEmbed(\"#vis\", spec).then(result => console.log(result)).catch(console.warn);\n\n});\n}\n\naffixScriptToHead(\"https://cdn.jsdelivr.net/npm/vega@5\");\naffixScriptToHead(\"https://cdn.jsdelivr.net/npm/vega-lite@5\");\naffixScriptToHead(\"https://cdn.jsdelivr.net/npm/vega-embed@6\", () => { \n console.log(\"The scripts has been correctly loaded.\");\n nr.send({topic: \"FROM UI\", payload : \"The scripts has been correctly loaded.\"})\n // console.log(this);\n //console.log(nr);\n console.log(vegaEmbed)\n myJS() // run main function after scripts\n })\n\n\n\n</script>\n\n\n\n\n","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","className":"","x":750,"y":640,"wires":[["b7e50c3d856e85c5"]]},{"id":"b7e50c3d856e85c5","type":"debug","z":"5847b7aa62131d37","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":960,"y":640,"wires":[]},{"id":"66d1189f909dbae5","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"},{"p":"vega","v":"[1,2,3,4]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":540,"y":640,"wires":[["f6b104981899da0e"]]},{"id":"cecf42695640eca4","type":"ui_group","name":"Default","tab":"39a6d442788cfb84","order":1,"disp":true,"width":"24","collapse":false,"className":""},{"id":"39a6d442788cfb84","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]