How to make DOM not to wait till javascript is downloaded and just open the page?

That's easy. Just add async attribute to the script tag. DOM will be ready before Javascript is downloaded, so the visitor will see contents of the page faster. It's always better, when your JavaScript is only used for user's interaction.

Before (DOM is ready only when jquery.min.js is loaded):

<html>
<head>
<script src="jquery.min.js"></script>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>

After (DOM is ready before jquery.min.js is loaded):

<html>
<head>
<script async src="jquery.min.js"></script>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>

No comments:

Post a Comment

You can ask IT questions in comments!