What is the difference in behavior / performance when including tag in body or head part of html document. Also i noticed that google analytics is usually embedded at the end of body. why is开发者_JAVA技巧 that?
Most of the time you want to include scripts at the bottom of the body section. The basic reason is to ensure that the page (and consequently the DOM) has fully loaded before any javascript is executed upon it.
Additionally, since downloading scripts blocks the browser from downloading anything else at the same time, the page will appear to load faster if the page elements are loaded before the script. However, unless you are a huge website that gets lots of traffic like Yahoo or Google, you probably do not need to consider this.
From Yahoo! Developers Network: Put Scripts at the Bottom
精彩评论