in reply to Passing javascript last in CGI

"As it stands, all of the javascript files are sent in the head element, ...."

So, don't put the js in the head. Nothing in HTML4.01 (I don't know about HTML5) bars inclusion of your script(s) (or links to your script(s)) in the body of the html.

Adapted from http://w3schools.com/dhtml/tryit.asp?filename=trydhtml_intro, where it is included in the head... but cf, this mod:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/T +R/html4/strict.dtd"> <html> <head> <title>js test</title> </head> <body> <h1>Hello.</h1> <p> This is a para with a 1-char indent.</p> <script type="text/javascript"> document.write("Hello World!") </script> <script type="text/javascript"> cc=0; function changeimage() { if (cc==0) { cc=1; document.getElementById('myimage').src="bulbon.gif"; } else { cc=0; document.getElementById('myimage').src="bulboff.gif"; } } </script> <!-- does not pass strict for lack of an alt in the images --> <img id="myimage" onclick="changeimage()" src="bulboff.gif" alt="bulb" + width="100" height="180" /> <p>Click to turn on/off the light</p> </body> </html>

Replies are listed 'Best First'.
Re^2: Passing javascript last in CGI
by Anonymous Monk on Jul 26, 2012 at 05:43 UTC

    So, don't put the js in the head. Nothing in HTML4.01 (I don't know about HTML5) bars inclusion of your script(s) (or links to your script(s)) in the body of the html.

    This might be outdated information, but putting things in the body actually meant that many browsers had to request and load the javascript (why, it might contain document.write!) before continuing to parse the page -- hence, slowdown.

    I'm very much unsure how browsers load a javascript in a head block, but any slowdown should only affect the first page load (when the scripts are cached), and the OP's concerns are best mitigated by setting up decent caching behaviour and not storing scripts on any external servers whose performance he cannot control.