0

What are the advantages of putting external javascript calls at the bottom of the page, just before the:

</body>

tag, as opposed to putting them within the:

<head></head>

Thanks.

Strontium_99
  • 1,771
  • 6
  • 31
  • 52

2 Answers2

3

It's always better to put your javascript just before the closing </body> tag, because it will guarantee that your styles and html code will load before any scripts not causing any delay.

Otherwise, your heavy scripts will load first with blank screen, and only after they are loaded, your page will appear.

Respect your users and let them navigate your website as soon as possible.

Maksim Gladkov
  • 3,051
  • 1
  • 14
  • 16
  • Nice one. Just the clear cut answer I was looking for. Thanks for the response. – Strontium_99 Feb 14 '14 at 12:14
  • Sometimes you want the script to load sooner. Sometimes it is more efficient to have it load sooner because even though script elements are blocking you can get better performance with parallel downloads. It isn't as clear cut as you make it out to be. – Quentin Feb 14 '14 at 12:19
  • It is usually a bad practice to load scripts first. You want users to be able to navigate the page first and then you enable some special features with scripts for them. Parallel downloads are great, but still they can handle only 5 parallel requests per domain, etc. So it is not always so fast. – Maksim Gladkov Feb 14 '14 at 12:23
2

It is always best option to load the javascript before just closing the body.

It improve the javascript action which are scripted to execute on page load.