Currently, I am dynamically injecting HTML into a page using JQuery AJAX. The injected HTML contains script and link tags for JS and CSS files respectively. The issue I am facing is that my initPage()
function runs before the script containing its definition has finished loading.
Below is an example of the HTML received from the AJAX call:
<script type='text/javascript' src='//domain.com/js/fillip.js'></script>
<script type='text/javascript' src='//domain.com/js/fillip2.js'></script>
<link href='//domain.com/css/fillip.css' rel='stylesheet'>
<iframe src='//domain.com/mypage'></iframe>
<script type='text/javascript'>
$(function(){
initPage();
});
</script>
I am looking for a solution to execute additional JavaScript only after all scripts have been loaded, with the flexibility to handle varying numbers of required script and CSS file dependencies. Bonus points if the solution can also accommodate waiting for CSS files to load.