Javascript file not being called at appropriate time in 2.0?

R

Roy

Quick 2.0 question. I have this script in my <HEAD> tag:

<script TYPE="text/javascript" src="js/myscripts.js"></script>

I'm using the callback functionality of 2.0 and the page doesn't work
correctly because the javascript file is clearly being loaded at some
time that is incompatible with the back-end code. HOWEVER, when I copy
and paste the actual script (the javascript code, not the file) in the
exact same place in the <HEAD> tag, everything works great.

Why is that?
 
B

bruce barker \(sqlwork.com\)

when you link to script source, its loaded async when resources are
available. the browser will typically queue download requests as it only
allows 2 downloads at once. inline script is processed as soon as its
parsed. you can safely call linked code after the onload event fires in the
browser.

so in inline script you can:

line 1<br>
<script>document.write("line2<br>");</script>
line 3<br>

and get what you expect.


note: in the browser onload event fires after all content is parsed (not
neccessary rendered).

-- bruce (sqlwork.com)
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top