Skip to content

Instantly share code, notes, and snippets.

@Weiyuan-Lane
Created February 3, 2019 05:28
Show Gist options
  • Save Weiyuan-Lane/dbafebaac2959c414f0c5a3f24b311b8 to your computer and use it in GitHub Desktop.
Save Weiyuan-Lane/dbafebaac2959c414f0c5a3f24b311b8 to your computer and use it in GitHub Desktop.
Defer and async script loading example
<html>
<head></head>
<body>
<!-- Script loading, parsing and execution after html content below
is rendered, or what is known as "DOMContentLoaded" event -->
<script src="script_one.js" defer="defer"></script>
<!-- Same as above, except it maintains order of execution after
"script_one" -->
<script src="script_two.js" defer="defer"></script>
<!-- Loading doesn't block rendering of DOM elements, but when
the script is executed is not deterministic. Best used for
independent components -->
<script src="script_three.js" async="async"></script>
<!-- Rendered in page first -->
<p>I'm an alpaca</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment