KoreaStudent
KoreaStudent

Reputation: 47

Should I leave the script tag empty if I use an external script file?

I mean, if I use JavaScript in an external file(write script code in another file, not in HTML file).

I write this code in my HTML file <script src="filename.js"></script> But this code works only if I left the tags empty.

So I'm wondering that if we use JavaScript in an external way, should I leave the tag empty as I mentioned?

Upvotes: 1

Views: 180

Answers (1)

Nick
Nick

Reputation: 1629

Yes. It's important to note that a script element using the src attribute should not include additional Javascript code between the <script> and </script> tags. If both are provided, the script file is downloaded and executed while the inline code is ignored.

Reference

Note that html5 allows comments inside an external script tag. Reference html5

Upvotes: 1

Related Questions