Where to insert JavaScript Libraries and CSS in my HTML code?

前端 未结 4 685
暖寄归人
暖寄归人 2021-01-16 00:57

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

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 01:33

    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(){}).

    Back to the loading problem

    People who put their

提交回复
热议问题