Where to put Javascript scripts? in the or in the ?

The most common thing is to place the Javascript scripts just before the closing tag

This is done this way because generally the Javascript has to be started after the browser has processed the HTML. It doesn’t do much good for the browser to process the Javascript when the user hasn’t yet been able to see the content of the page. Also, Javascript often has to operate on page elements, to modify them dynamically, and this has to be done when the elements have been loaded by the browser. For all these reasons, it is usually placed before closing the tag.

Putting the scripts in the can cause the browser to have fun downloading Javascript that it doesn’t need to run prior to loading the page content, which can reduce load time and therefore performance. Depending on the size of the Javascript code and the number of files to be loaded, this may be more or less representative, but the optimization of placing the scripts before the does not usually hurt.

See also  delay in javascript
Loading Facebook Comments ...
Loading Disqus Comments ...