Sometimes, we want to make JavaScript execute after page load.
In this article, we’ll look at how to make JavaScript execute after page load.
How to make JavaScript execute after page load?
To make JavaScript execute after page load, we use the defer attribute.
For instance, we write
<script src="script.js" defer></script>
to add the defer attribute to the script tag to make script.js load after the page is loaded.
Conclusion
To make JavaScript execute after page load, we use the defer attribute.