Where should JS scripts go in an HTML file?

后端 未结 6 1593
遇见更好的自我
遇见更好的自我 2020-12-14 01:48

If you have JS code which is intended to run as part of loading/building the page, where in the HTML should this go? For instance modifying a

or add
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 02:32

    For best performance place your JavaScript files at the BOTTOM of the HTML page you are serving.

    To ensure that everything is set when you try to use it, execute only after the DOM is ready (there are multiple variations of this, my advice: Use a JavaScript Library).

提交回复
热议问题