views:

34

answers:

3

Today I was looking for website optimization content and I found an article talking about move JavaScript scripts to the bottom of the HTML page. Is this valid with W3C's recommendations? I learned that all JavaScript must be inside of head tag... Thank you.

+2  A: 

From the documentation:

This element may appear any number of times in the HEAD or BODY of an HTML document.

Tgr
A: 

Yes, the SCRIPT element is allowed as child of the BODY element:

<!ELEMENT BODY O O (%block;|SCRIPT)+ +(INS|DEL) -- document body -->
Gumbo
A: 

It is valid. Script tags can be in both the head and body. Moving the script tags to just prior to the closing body tag will significantly boost rendering time in IE, because scripts block parallel downloads.

And what about another browsers? It just increase speed in IE?
Thomas
You would need to read the research of the person who proposed this claim: http://oreilly.com/catalog/9780596529307
This is true for every browser. Scripts can interact with the page in an unpredictable way (specifically they can change what needs to be loaded) so browsers suspend all other activities while they load and execute a script (except when the `defer` attribute is set). OTOH placing the scripts at the end of the body means that the user gets to interact with the javasript-less version of the page for a short time, which might have weird effects.
Tgr