Load ordering of dynamically added script tags

I can mention some alternatives to overcome that requirement: Use a library to inject dependencies (AMD or CommonJS modules) Just use modules. ES2015: import/export, or CommonJS: require(). Create the script tag programmatically and set the callback onload in order to react when the script has been loaded asynchronously. The attribute async = true is set … Read more

Waiting for dynamically loaded script

Add an ID to your script file so you can query it. <script id=”hljs” async src=”https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/highlight.min.js”></script> Then add a load listener to it in JavaScript <script> var script = document.querySelector(‘#hljs’); script.addEventListener(‘load’, function() { hljs.initHighlightingOnLoad(); }); </script>

load and execute order of scripts

If you aren’t dynamically loading scripts or marking them as defer or async, then scripts are loaded in the order encountered in the page. It doesn’t matter whether it’s an external script or an inline script – they are executed in the order they are encountered in the page. Inline scripts that come after external … Read more