Why put JavaScript in head

后端 未结 8 1890
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 11:18

If it is perfectly acceptable to put JavaScript right before what is a good reason to keep it in the ?

Based on t

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 11:45

    Thats a Question like "windows" or "mac" I think, If you put all your JS Source in the Head Section of the Website your are quit strong to the W3C. The Other Case is everthing in the Head must be loaded befor the body Element. And befor the DOM is correctly loaded. JavaScript Frameworks like jQuery have Functions like $(document).ready() to check the complete DOM is loaded. So you could do all your JS in the Head Tag. My Preference is to load all JS at the End of the Body but this decision goes to each Developer at its own :)

提交回复
热议问题