S
S
seredaes2016-02-17 14:19:13
JavaScript
seredaes, 2016-02-17 14:19:13

Connect libraries or load in one file?

My colleague stuffs all JS libraries (his own and others') into one file! And then loads this pig one huge.
I prefer to keep everything separate, how can I disable it on some page, etc. Although the friend says that all this is cached once and there are no problems!
Tell me what do you think about this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2016-02-17
@seredaes

Common libraries (jQuery, React, lodash, etc.) with CDN (separate scripts). Everything else in one file.

A
Alexey Nikolaev, 2016-02-17
@Heian

In my opinion, there is a reason for this if it is loaded asynchronously. Then this file will not affect the page loading speed even for the first time, but while the user sticks where he got to and what needs to be done here, the file will load and all interactive elements will be connected on the page.
Of course, pieces of code that are critical for the functionality must be moved to a separate file and loaded separately (for example, if your masonry grid is built exclusively on js), but such moments are not always found.
Again, asynchronous loading of scripts in case they are scattered over several files and connected in this way is difficult, because there is no guarantee that the required library will be loaded before it is called (they usually determine the readiness of scripts in $(document).ready or, if in pure js, window.load, which will not work with asynchronous loading), and it is easier in this case to abandon this method .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question