Created
May 24, 2011 16:46
-
-
Save andykent/989092 to your computer and use it in GitHub Desktop.
Simple example showing advantages of async JS loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alert('Hello from alert.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript"> | |
(function() { | |
var t = document.createElement('script'); t.type = 'text/javascript'; t.async = true; t.src = "./alert.js"; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(t, s); | |
})(); | |
</script> | |
</head> | |
<body> | |
<p>You should see me before the alert fires :)</p> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="./alert.js" type="text/javascript" charset="utf-8"></script> | |
</head> | |
<body> | |
<p>The alert will fire before you see me and you'll be waiting ages :(</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment