Single or multiple javascript blocks?

Hey guys,

I was just wondering if it’s recommended to have all your javascript contained in a single unified block or if it’s okay to have them spread out across the document? I find the second approach ensuring JS is located near code that is directly associated increases readability, but I’m worried it may have a negative effect on performance, however minor.



Placing all the JavaScript calls either at the end of the head or at the end of the body is the best way of making your page as maintainable as possible. It also makes it easier to comment them all out in order to easily test the without JavaScript version of the page in browsers that do not allow JavaScript to be easily turned on and off.

Having the script code spread out across the document strongly impacts page loading performance, because the web browser must stop all of its loading each and every time it comes to a script block, where it has to finish loading and executing that part of the script, before the browser is allowed to carry on loading parts of the page.

See these Best Practices for Speeding Up Your Web Site

Thank you guys for the feedback - exactly the sort of clarification I was looking for!