Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check when async javascript file is loaded [duplicate]

I'd like to "bootstrap" my page only after all async files have been loaded. Is there a way I can be notified when an async file has been loaded?

index.html

<script src="fileone.js" type="text/javascript" async></script>
<script src="filetwo.js" type="text/javascript" async></script>
<script src="bootstrap.js" type="text/javascript" async></script>
like image 825
Steven Wexler Avatar asked Feb 09 '23 09:02

Steven Wexler


1 Answers

Giving one of your scripts an ID...

<script src='fileone.js' type='text/javascript' async id='script_1'></script>
<script>
    document.getElementById("script1").onload = script.onreadystatechange = function(){ alert("Script loaded!"); }
</script>
like image 103
MyUser Avatar answered Feb 11 '23 00:02

MyUser