EN
HTML - load script element in async mode
3 points
In this article, we would like to show you how to load script element in async mode working with HTML.
Quick solution:
xxxxxxxxxx
1
<script src="/path/to/script.js" async></script>
In this example, we use the async
property to asynchronously load the jQuery library from an external server (CDN).
xxxxxxxxxx
1
<html>
2
<head>
3
<script>
4
5
function handleLoad() {
6
console.log('Script loaded successfully.');
7
};
8
9
function handleError() {
10
console.error('Script loading error.');
11
};
12
13
</script>
14
<script async
15
src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"
16
onload="handleLoad()"
17
onerror="handleError()">
18
</script>
19
</head>
20
</html>