Link to Multiple JavaScript Files in a Single HTML Document


show more Learn how to link to multiple JavaScript files—your own files, JavaScript libraries, even Google Analytics scripts—in a single HTML document. Simon Allardice explains the two keys to linking to multiple JavaScript files while keeping your page load times to a minimum: the amount of script tags, and their order. show less
please wait ...

Linking to multiple JavaScript files

So I have suggested that your default way of including JavaScript on your page is to have a script tag right before the closing body tag that just links to a separate JavaScript file. And it is also quite common to see several script tags here, and particularly common when it comes to having both your own code and one or more JavaScript libraries and perhaps a link to a Google Analytics JavaScript and so on. But two things to keep in mind: you want to keep the amount of script tags here at a minimum, and the order of them matters. So, why minimum? Well, just be aware that every JavaScript file you link to is a separate request the browser needs to make to the web server.

The browser gets the HTML and moves down through it. It sees the link to the JavaScript and makes a call to the server for that first JavaScript file. It then waits for that file to finish downloading, and then, and only then, moves on to the next one, calls the web server for that file, and waits again. And that order cont...

Linking to multiple JavaScript files
Video duration: 2m 11s 5h 31m Beginner

Viewers:

Learn how to link to multiple JavaScript files—your own files, JavaScript libraries, even Google Analytics scripts—in a single HTML document. Simon Allardice explains the two keys to linking to multiple JavaScript files while keeping your page load times to a minimum: the amount of script tags, and their order.

Subjects:
Developer Web
Software:
JavaScript
Author:
please wait ...