问题
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.
回答1:
From the documentation:
This element may appear any number of times in the HEAD or BODY of an HTML document.
回答2:
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.
回答3:
Yes, the SCRIPT element is allowed as child of the BODY element:
<!ELEMENT BODY O O (%block;|SCRIPT)+ +(INS|DEL) -- document body -->
来源:https://stackoverflow.com/questions/2812496/javascript-tags-performance-and-w3c