E
E
Eduards Vigulis2015-09-11 12:21:07
css
Eduards Vigulis, 2015-09-11 12:21:07

Do I need to put many small JS files into one big one?

There is a project on AngularJS, at the moment it has about 80 js files.
The question arose: should they be folded into one?
My employer says: "if you upload 10 files asynchronously, 100kb each, it will be faster than one 1MB file" i.e. it’s not necessary to add up, but I think that it would be more correct to give JS in one big piece, but I can’t provide any arguments to refute his point of view.
Tell me who is right in this situation? How to do it right?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
F
FeST1Val, 2019-04-09
@Mars1k

There is a good optimization program that uses many optimization methods without losing quality. Well, if you have a picture without transparency, then it's better to make jpg) another stupid optimization option)
FileOptimizer

J
Jupiter Max, 2019-04-09
@vardoLP

Ask him. what he meant. Optimized can be understood as resizing for monitors (adaptability), or can be understood as reducing the size in kb. My clients often say this.

L
Lone Ice, 2019-04-09
@daemonhk

Photoshop option:
Quality: 60 (no longer needed for the web)
Tick progressive (progressive loading)

S
Sergey, 2015-09-11
@AIS

If you are using HTTP2, then it is not necessary, but it is unlikely.
And if you upload 80 files of 10kb each, then it will be slower than 10 files of 100kb each, since the cost of establishing a connection will be more than the waiting time for the delivery of the next portion of data.
The browser makes requests for resources in parallel (you can look in the browser debugger, there is also information about who is blocking the download), so downloading several files will be faster than downloading one large one. But, even taking into account keep alive, the browser cannot fully reuse in this connection scenario, and it will produce them in large numbers, and the more of them, the greater the load on the server, the slower the static will be. So a balance needs to be found.
I would suggest splitting everything into:
- angular.js
- vendor.bundle.js - all 3rd party modules and stuff
- app.bundle.js - all application files.
then yes. asynchronous loading will be faster.

D
Denis Ineshin, 2015-09-11
@IonDen

Not only possible but also necessary:
​​1. Build via Grunt/Gulp
2. Minified
3. Compressed with gzip
4. Cached by the browser
5. Uses only 1 request per server.
When loading a site, different browsers have a limited number of simultaneously executed requests (on mobile devices, there are generally few), besides, you have not only JS files there, there are also css, pictures, etc. They all line up to be loaded. So, in 99.9% of cases, loading one JS file will always be faster than loading several.

S
Stalker_RED, 2015-09-11
@Stalker_RED

Parallel loading can only be beneficial if you don't hit the maximum number of connections. And taking into account the fact that in addition to js files, you also need to load css, images, and other resources, it’s quite easy to hit the limit.
Here is a not very recent (~two years ago) but list of supported number of connections onedev.net/post/231

G
Gluck Virtualen, 2015-09-12
@gluck59

работодатель говорит: "если загрузить асинхронно 10 файлов по 100кб то это будет быстрее чем один 1МБ файл"

Работодатель тупенький, это нормально.
Аргумент простой: создайте 1000 файлов на диске, общим весом в Х мегабайт.
Создайте рядом один файл таким же весом.
Предложите работодателю скопировать то и другое по очереди. И сравнить время.
Думаю, этого эксперимента хватит даже для самых упоротых.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question