Async Vs Defer
Async Vs Defer
Async Vs Defer
com
HTML 101
async vs defer in <script> tags
root
Manish Poduval
1/8 rootlearn.com
What is it ?
We’ll understand the difference in using the async and defer
attributes in <script> tags in your HTML page
ways to load JS files
root
<script src="...."></script>
Manish Poduval
2/8 rootlearn.com
<html lang="en">
<head>
root
<script src="./index.js"></script>
</head>
<body>
Hey lo World!
without async or defer
</body>
</html>
Manish Poduval
3/8 rootlearn.com
<html lang="en">
<head>
without async or defer
root
</head>
<body>
Hey lo World!
<script src="./index.js"></script>
</body>
</html>
Manish Poduval
4/8 rootlearn.com
using async
<html lang="en">
<head>
root
<script async src="./index.js"></script>
</head>
<body>
Hey lo World!
</body>
</html>
load
parse execute parse
Manish Poduval
5/8 rootlearn.com
<html lang="en">
<head>
root
<script async src="./index1.js"></script>
</head>
<body>
Hey lo World!
</body>
</html>
load 2
load 1
parse execute 2 execute 1 parse
Manish Poduval
6/8 rootlearn.com
using defer
<html lang="en">
<head>
root
<script defer src="./index.js"></script>
</head>
<body>
Hey lo World!
</body>
</html>
load
parse execute
Manish Poduval
7/8 rootlearn.com
<html lang="en">
<head>
root
<script defer src="./index1.js"></script>
</head>
<body>
Hey lo World!
</body>
</html>
load 2
load 1
parse execute 1 execute 2
t
Manish Poduval
1 2 3