- DOM elements below the script tag can’t be handled because script cannot see them and can’t add handlers.
- If there is a bulky script on the start of the page then it block the rendering of the html page and user cannot see the page content till the script gets downloaded and run.
<script defer src="/js/jquery.min.js">
</script>
<script async src="/js/extras.min.js">
</script>
Load types of JavaScript.
1. Normal
In the Normal loading of the JavaScript as shown above with the help of the progress bar the html files are loaded and as soon as it encounter the script tag it stops and downloads the script and executes it and then it loads the rest of the html.
2. Async
In Async loading the JavaScript file is loaded asynchronously with html file and and as soon as the downloading is done it gets executed before the html.
3. Defer
But in Defer loading the script is loaded asynchronously with html file but it delays the execution of the JavaScript file till the html is loaded and rendered then only the JavaScript is executed reducing the wait time of the users and to interact with the page.