In this snippet
Lets assume th
that is because you cant import a script like that and in the same script element run javascript... because the external script will override your written javascript.... put them in different tags... also for a faster js import make a mock js src
If you had the below code and didn't want your alert('hi') to fire until all scripts have downloaded, you can wait for the document ready event. You can do this using jQuery, or with vanilla JavaScript.
<script src="takes very long to download" type="text/javascript"></script>
<script type="text/javascript">
alert('hi');
</script>
To defer until all scripts have loaded using jQuery:
$( document ).ready( function () {
alert('hi');
});
alert('hi')
would never fire, as the script
tag supports either inline code or external file code..
Read the specs at http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1
The script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.
No. The presence of a src
attribute will cause the descendant nodes of the element to be ignored.
If you had two script elements, then the second script would still always execute second because script elements are blocking.
Only if you had two script elements and the first had defer or async attributes could the second execute before the first.