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

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #167915
    alston
    Participant

    Hello,
    I’ve only worked with javascript and jquery code a little, using pre-coded plugins to accomplish certain things.

    I’ve read that putting javascript code just before the closing <body> tag so that it does not slow the page load, but is this always the case? Is this also the case with jquery?

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

    Thanks.

    #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

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.