-1

Many times I have come across javascript script includes some of them are placed in the head portion and some are placed at the end of the body. And in some cases of jQuery I have seen the same. Can anyone tell me what is the difference and significant between putting scripts in the head or at the end of the body?

tokyovariable
  • 1,656
  • 15
  • 23
  • 5
    Did you try searching before you asked this question? This has been asked **many** times before.... [Where to place Javascript in a HTML file?](http://stackoverflow.com/questions/196702/where-to-place-javascript-in-a-html-file) – Christian Apr 22 '15 at 06:47
  • there is no such difference, it's upto you – Amit Soni Apr 22 '15 at 06:48
  • 3
    @AmitSoni it's different, in HTML parser you have a recursive descent parser; top-down parser – ale Apr 22 '15 at 06:49
  • 3
    @AmitSoni There is a [difference](https://developer.yahoo.com/performance/rules.html#js_bottom), it does matter, it's not just personal preference. – SubjectCurio Apr 22 '15 at 06:49
  • @AmitSoni: Obviously, it matters. There's a reason why we prefer to place it at the end of body. – Sandeep Nayak Apr 22 '15 at 06:49
  • Please do some search before asking. It has been asked many times. [link](http://stackoverflow.com/questions/436411/where-is-the-best-place-to-put-script-tags-in-html-markup) – SM Ahmed Apr 22 '15 at 06:51

1 Answers1

0

Yahoo recommends to put all scripts at the bottom of your page.

The problem caused by scripts is that they block parallel downloads. The HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames...Read More

It is often seen that jQuery is placed at the top, this is to avoid any dependacy issues that you might face in your custom code.

Community
  • 1
  • 1
Siddharth Patel
  • 193
  • 1
  • 2
  • 15