where to place my script tag before closing of</body> or after it [duplicate]

和自甴很熟 提交于 2020-06-17 18:23:57

问题


As we many of know that we have to include external jsscript file at the end of page. for performance and usability purpose.

I want to know the correct place where to place it.

means

<boby>
<!--html here -- >
<script src= ""> <!--  here ???  -- >
</body>
<script src= ""><!--  here ???  -- >

before the closing of script tag or after the closing of script . Is there any avantage of putting inside or outisde of body tag.

Thanks in advance..


回答1:


Placing it after the body isn't even an option, script tags cannot go there. That would result in an invalid HTML document.




回答2:


Hey you should put this before closing of body tag, but at the end where all other elements end Like

    <body>
    <h1></h1>
    ... 
    .... 
<!-- you shud place here -->
<script>
</script>
   </body>

And to your second question, you cannot just put after body tag, except in <head></head> section. This is called calling js asynchronusly (in body tag generally in footer section )



来源:https://stackoverflow.com/questions/24464786/where-to-place-my-script-tag-before-closing-of-body-or-after-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!