0

There are two simple ways to include Javascript in a HTML document.

Way 1 (script tags):

<script> console.log("Hello world") </script>

Way 2 (external file):

<script src="helloworld.js"> </script>

Assuming that helloworld.js contains the single line console.log("Hello world"), are these inclusions exactly equivalent? If not, what is the difference?

If the contents of the script were more complicated, would the answer to this question change?

preferred_anon
  • 538
  • 4
  • 11
  • 2
    It's equivalent. The browser pauses, loads the file, processes it, and only then continues parsing the HTML. Whether you should use inline code is of course a different story, and if the script is on another server, it might not load or take a long time to load, making the page hang. (edit: not a duplicate of that question imo) –  May 06 '19 at 09:25
  • yes it's equivalent – Abolfazl Mohajeri May 06 '19 at 09:26

0 Answers0