Where in the HTML file should Jquery and Bootstrap be placed?

前端 未结 3 1610
面向向阳花
面向向阳花 2020-12-24 02:30

Curious at to where I place my Jquery and Bootstrap files. They recommend that you always place at the bottom for performance purposes yet when I check sites that use Jquery

3条回答
  •  失恋的感觉
    2020-12-24 02:54

    Typically stylesheets in the head and scripts before the closing tag:

    
      
        
        
      
      
        
        
        
        
      
    
    

    You'll want files from vendors such as jQuery and Bootstrap to be included before yours. This means that:

    • CSS: You can override their styles with your own*
    • Scripts: You have access to any objects added to the global scope such as window (jQuery adds $, for example)

    However, if you require a script to be available before your content loads (such as Modernizr), then putting it in the ensures it's ready before any of your content.

    Including scripts at the bottom ensures that the actual page content is loaded first; when the scripts are finally downloaded the content (DOM) will be ready for your scripts to manipulate.

    * assuming your selector specificity is at least equal to those in your vendor CSS

提交回复
热议问题