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

前端 未结 3 1615
面向向阳花
面向向阳花 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:42

    Bottom is best to place all your script references at the end of the page before .It should look like below in normal page.

    
     
       
     
     
       
     
    
    

    Although in some cases it may be necessary to load JavaScript before page load if any of your function need to access JavaScript before Page Load.Specially if you are working with JQuery UI And Bootstrap.

    You can decorate your script tags with the defer attribute so that the browser knows to download your scripts after the HTML has been downloaded:

    
    

    or

       
    

    When present, it specifies that the script will be executed asynchronously as soon as it is available.

    http://www.w3schools.com/tags/att_script_async.asp

    If you need script to access in page for use then script need to available before using it. Although it need to be sure the browser support defer="defer". Async is supported by all major browsers.

    Javascript by default block any other parallel downloads. So if you have many tags in the head, calling on multiple external scripts will block the HTML from loading, thus greeting the user with a blank white screen, because no other content on your page will load until the java script files have completely loaded. Another advantage to load script in bottom is that any error caused by external script will not stop the page from Loading to browser.

    Style css need to present in top to access in page.

提交回复
热议问题