Tobias Baumeister
Tobias Baumeister

Reputation: 2147

Loading many javascript files

Is it better to put every sitewide javascript function in one file or can I split them in more files (I've got about 15 at the moment).
Since my visitors are complaining about long loading times when calling the site - so I'm trying to find the reason for this.

So does it make any differences at all?

Upvotes: 0

Views: 60

Answers (1)

Luca Fagioli
Luca Fagioli

Reputation: 13359

Yes, you will get a benefit.

This is because the HTTP protocol will make a request for every single file, sequentially and synchronously, and since every request carries a data payload along with a request-response delay, by unifying all the files in one, you will simply have just one request-response delay and a single data payload.

You can get a visual explanation on that, by viewing the Network tab of the Chrome DevTool, or any other network analyzer tool.

Moreover, you can minify the obtained main javascript file, by using one of the many online tools made for this purpose. For example, this one.

Be aware to keep the order of your javascript files when unifying them, if they are dependent on each other.

Upvotes: 2

Related Questions