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

Discussion in 'Javascript' started by Joe Nine, Mar 28, 2010.

  1. Joe Nine

    Joe Nine Guest

    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.
     
    Joe Nine, Mar 28, 2010
    #1
    1. Advertising

  2. Joe Nine

    David Mark Guest

    Joe Nine wrote:
    > 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).
     
    David Mark, Mar 28, 2010
    #2
    1. Advertising

  3. Joe Nine

    Joe Nine Guest

    David Mark wrote:
    > Joe Nine wrote:
    >> 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).


    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.
     
    Joe Nine, Mar 28, 2010
    #3
  4. Joe Nine wrote:

    > David Mark wrote:
    >> Joe Nine wrote:
    >>> 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).

    >
    > 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
    --
    Danny Goodman's books are out of date and teach practices that are
    positively harmful for cross-browser scripting.
    -- Richard Cornford, cljs, <cife6q$253$1$> (2004)
     
    Thomas 'PointedEars' Lahn, Mar 28, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcelo Birnbach [MS]
    Replies:
    0
    Views:
    3,330
    Marcelo Birnbach [MS]
    Jun 28, 2003
  2. Marshal Antony
    Replies:
    3
    Views:
    7,910
    Charlie@CBFC
    Jan 21, 2004
  3. Udo Corban
    Replies:
    0
    Views:
    3,854
    Udo Corban
    Jan 23, 2004
  4. Andrew Chalk
    Replies:
    1
    Views:
    315
    Michael Geary
    Aug 28, 2003
  5. rbt
    Replies:
    8
    Views:
    367
Loading...

Share This Page