Can code in a script file start running before file loaded?

J

Joe Nine

If you've got some inline code in a JS file at the top of the file, is
that allowed to start running (and by that I mean will the browser start
executing it) before the entire JS file has loaded? Is that possible?

I don't want it to be possible, I want to be sure that it won't happen.
 
D

David Mark

Joe said:
If you've got some inline code in a JS file at the top of the file, is
that allowed to start running (and by that I mean will the browser start
executing it) before the entire JS file has loaded? Is that possible?

Inline code in a JS file? If you mean simply a JS file, then the answer
is no (the browser won't even parse the code until after the file is
downloaded).
 
J

Joe Nine

David said:
Inline code in a JS file? If you mean simply a JS file, then the answer
is no (the browser won't even parse the code until after the file is
downloaded).

Thanks, yes I did mean in a separate JS file. I kind of new that code
that's inline in the HTML page in a script tag could start running
before the closing script tag. That's why I always code block structured
so I'm not using any var or func that wasn't declared above. I'm glad to
hear that this can't happen in a separate JS file though.
 
T

Thomas 'PointedEars' Lahn

Joe said:
Thanks, yes I did mean in a separate JS file. I kind of new that code
that's inline in the HTML page in a script tag could start running
before the closing script tag. That's why I always code block structured
so I'm not using any var or func that wasn't declared above. I'm glad to
hear that this can't happen in a separate JS file though.

You are not making sense.

1. There are no files in HTTP, there are resources.
2. There are no script tags in (X)HTML, there are SCRIPT/`script'
_elements_.
3. David has not confirmed that "code ... could start running before
the closing script tag".
4. There is no "closing script tag", there is an _end tag_ of the
SCRIPT/`script' _element_.
5. ECMAScript implementations are usually not block-scoped.


PointedEars
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top