41

Loading Script Files Dynamically

In this Chapter

  • Learn how to load script files efficiently

  • Learn how to use the appropriate script load events to customize when your code runs

In the previous Chapter 40, “Page Load Events and Other Stuff,” a part of what we looked at were the various ways we have to load and run external JavaScript files in our pages. All of these various ways assumed we knew exactly what script file we wanted to load with the src attribute already pointing to our file:

<script src="https://www.example.com/foo.js">
</script>

Now, what if you were in the situation where you didn’t know what script file you wanted to load at the time your page is loading? What if you had to choose between ...

Get Javascript Absolute Beginner's Guide, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.