Loading Javascript Scripts to Browser

T

tdan

When loading Javascript files with <script> tags in your HTML,
do the files load AND run sequentially or does the
HTML simply load the files and run them simultaneously.

If not, how can you force them to run sequentially?
 
B

Bart Van der Donck

tdan said:
When loading Javascript files with <script> tags in your HTML,
do the files load AND run sequentially or does the
HTML simply load the files and run them simultaneously.

If not, how can you force them to run sequentially?

The execution order is identical to their position in the web page
(top-down), consider:

<script type="text/javascript" src="1.js"></script>
<p>2</p>
<script type="text/javascript" src="3.js"></script>

If you want to change this behaviour, you might work with separate
functions and invoke them at the appropriate time.
 
T

tdan

OK - so just for clarification, the web page will NOT move onto loading
the next script until it is done executing the previous one. . . that
doesn't seem to be what my web app is doing.
 
M

Martin Honnen

tdan said:
OK - so just for clarification, the web page will NOT move onto loading
the next script until it is done executing the previous one. . . that
doesn't seem to be what my web app is doing.

Loading a resource like a script file and executing the script code in a
script file are two different steps. It is certainly possible that a
browser fetches the second file while executing the code in the first file.
 
B

Bart Van der Donck

tdan said:
OK - so just for clarification, the web page will NOT move onto loading
the next script until it is done executing the previous one. . . that
doesn't seem to be what my web app is doing.

..replace(/loading/,'executing');
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top