问题
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