Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
100
rated 0 times [  101] [ 1]  / answers: 1 / hits: 21224  / 13 Years ago, wed, november 23, 2011, 12:00:00

If it is perfectly acceptable to put JavaScript right before </body> what is a good reason to keep it in the <head>?



Based on the question JavaScript in <head> or just before </body>?
many answers state that the page will load faster if you put it right before the </body> tag.



However I don't see any sound arguments on why it should be kept in the <head>. I'm asking because I am not a very strong JavaScript developer and from everything I've read and seen, the standard is to keep most JavaScript code and external references in the the <head>.


More From » html

 Answers
65

Anything in the head must be completed before the body is loaded, so it is generally a bad idea to put javascript in there. If you need something while the body is loading, or want to expedite some ajax, then it would be appropriate to put it in the head.


[#88936] Tuesday, November 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anyssaarielles

Total Points: 415
Total Questions: 107
Total Answers: 92

Location: Greenland
Member since Fri, Jul 31, 2020
4 Years ago
;