Where should I declare JavaScript files used in my page? In <head></head> or near </body>?

后端 未结 12 948
后悔当初
后悔当初 2020-11-27 15:07

I was reading a tutorial and the author mentioned to include Javascript files near closing body tag () in HTML.

I was wonderi

12条回答
  •  迷失自我
    2020-11-27 15:44

    You should put JavaScript right before . Ideally, your HTML should function without JavaScript, so it should be one of the last things loaded.

    Bear in mind that you should use CSS to hide elements and not JavaScript. This avoids seeing elements appear and disappear as the page loads.

    You may also come across the following problem...

    Problem

    In this scenario, I'm going to use PHP as an example.

    Your footer.php file may currently look like this:

    
    
    
    
    

    But what happens on the rare occasions you want to add some

    And a footer-end.php file:

    
    
    

    And have your footer.php be simply:

    Then, on the rare occasions that you need to use a custom

    Doing it this way means you don't have to change all your previous code where footer.php is referenced.

提交回复
热议问题