Triggering Javascript at the Right Moment | Hugonweb Annotated Link Bibliography

https://stackoverflow.com/a/36096571

The best way to run javascript is in the head with the "defer" attribute. That immediately starts fetching the script, but waits to execute it until the whole page is parsed.

<!DOCTYPE html>
<html>
<head>
  <title>Title</title>
  <meta charset="UTF-8">
  <script src="blahblah.js" defer></script>
</head>
<body>

<p>Stuff here</p>

</body>
</html>