Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  170] [ 7]  / answers: 1 / hits: 15783  / 8 Years ago, wed, july 20, 2016, 12:00:00

I have two external javascript files within my html page.



I need to make sure that the first file, script1.js, is run before my second script, script2.js.



I have them within the body of my html page; how can I ensure that script2 is not used until the functions in script1 are run?



<!DOCTYPE html>
<html lang=en>

<head>
</head>

<body>

<!-- Script 1 -->
<script src=js/script1.js></script>

<!-- Script 2 -->
<script src=js/script2.js></script>
</body>
</html>

More From » jquery

 Answers
40

The browser will execute the scripts in the order it finds them. If you call an external script, it will block the page until the script has been loaded and executed.



So if your code is :



<body>

<!-- Script 1 -->
<script src=js/script1.js></script>

<!-- Script 2 -->
<script src=js/script2.js></script>
</body>


Script 1 will be run before Script 2.


[#61308] Sunday, July 17, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
morrismilom

Total Points: 230
Total Questions: 96
Total Answers: 114

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
;