I am little new to web development and when I was searching internet about other topics, I have seen many people has put popular JS Libraries in Different Places of
There is no so called "standard" method. The choice of where to put the lines boils down to one question: When will I need the library?
You see, web files loads line by line, let's take the following as an example of what I mean:
unchanged
#target
isn't altered because the script was loaded before the element did. Web files loads procedurally. When the line of JavaScript is loaded. It is executed immediately, but the target element isn't. So it couldn't change the element.
Even with jQuery, there is the same problem:
unchanged
Therefore, we often use $(function(){})
.
People who put their tags or
tags in the body (in front) or in the head, wanted to execute the script immediately, sometimes they won't use
$(function())
or document.onload
People who put their tags or
tags in the body (in the end) wanted to ensure all elements are loaded then execute the script or load CSS.
You should load independent resources such as jQuery first, then load dependent resources such as jQuery plugins. Then you try to decide when you want the resources to start loading, then put the lines in places.
You should put CSS links in the tag because you don't want visitors seeing unstyled content before loading the CSS files.
If you can't decide or don't care about the time, put every and
tags in the
.
Here is another post you might be interested in: Load and execution sequence of a web page?