Categories
JavaScript Answers

How to make JavaScript execute after page load?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *