When the HTML parser comes across a
<script> element to address the user wait-time in the website based on different scenarios.
The defer attribute specifies scripts should be executed after the HTML file is completely parsed. When the HTML parser encounters a
<script> element with the
Here is an example of the
<script src="example.js" defer></script>
When a script contains functionality that requires interaction with the DOM, the
defer attribute is the way to go. This way, it ensures that the entire HTML file has been parsed before the script is executed.
We want the “Codecademy” to be blue, not yellow! Each script tag re-styles the Codecademy logo, but the turnYellow.js executes last, making the font color
'yellow'. Add a
defer attribute to the turnBlue.js script to make it the last script that is downloaded and executed.