Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript where to insert javascript or jquery code Reply To: where to insert javascript or jquery code

#167920
Alen
Participant

Browser follows execution order of scripts as it encounters them. First downloading the script then executing it. If A.js is before B.js, A will be loaded and executed first, before B can be downloaded / executed. Generally, you would put JavaScript script tags in the bottom of the page, because JavaScript is blocking rendering (while it’s downloading), browser has to wait, so by placing the scripts at the bottom, we let other resources load then we load all the JS dependencies. This also helps with errors, if for some reason you’re including script at the top and script has some sort of error, it might render the rest of the page blank. So generally speaking it is preferred to put script tags before </body> tag. In the case of feature detection library like Modernizr, you would include this in the <head> since you want to detect certain features before you construct the DOM or do whatever needs to be done.

Now there are some Asynchronous Script Loading techniques, but I don’t want to confuse you even more. If you care to explore take a look at library http://www.labjs.com

Also, where are the best places to get well-coded javascript and jquery plugins from to use in web design?

http://www.unheap.com