Why put JavaScript in head

后端 未结 8 1886
被撕碎了的回忆
被撕碎了的回忆 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 :)

    0 讨论(0)
  • 2020-12-24 11:53

    The only reason to put JS in the head is for scripts that modify how the browser actually renders the page. For example, Modernizr.js is loaded in the head so that it can do things like add support for HTML5 elements and manipulate classes on the <html> tag before the page begins to render.

    Otherwise, your JS should be going in at the bottom of the page.

    0 讨论(0)
提交回复
热议问题