I have seen Scriptaculous.js file to include its required javascript files dynamically. Is there any better approach to include javascript dynamically.
For example,
Create a script tag, set the URL, add it to the document:
let script = document.createElement("script");
script.src = "https://example.com/your_script.js";
document.body.appendChild(script);
That's it. There are too many overly complicated answers on this page for such a simple task.
If you're using modern JavaScript, you can use dynamic importing with a syntax like await import(...). That's out of the scope of this answer, but you can read more about that here.