kyle
kyle

Reputation: 61

proper size for Javascript

I am working on minify and uglify my javascript files. I am wondering how big the proper size is. If I combine all js files into a file (with minifying and uglifying), it is bigger than 1mb. I guess, it's better to chop them into 2-3 files (200kb-300kb for each) instead of one big file (1mb).

Can anyone give a suggestion? like 100kb ~ 300kb or 1mb ~ 2mb

============ additional comment ============

I am using Django(Backend) & angularJS (Frontend). as far as I know, all js files for angularJS should be sent to user when index(root html file) html file sent. That's why the Concatenated js files (including external js file such as jquery, bootstrap, angular, media player and etc...) is more than 1mb.

Upvotes: 0

Views: 2551

Answers (3)

Ismaeel Yaghoubi
Ismaeel Yaghoubi

Reputation: 1

When using tools like Webpack the maximum suggested file size is 244 KB but as others mentioned, it depends on the project and there is no exact answer.

Reference

Upvotes: 0

a--m
a--m

Reputation: 4782

There is no correct answer for your question. Some recommendations, since you have a large app to load:

  • split up your app in modules and load the modules as you need, this way you can start the app quickly and the user will require the other modules as it uses the app.
  • show some visual feedback while you load the needed files, most common example is a spinning wheel, but it could be a pong game. The key is to entertain the user since no one wants to wait
  • use server and client cache, don't forget to add cache headers that leverage client cache
  • split up your build source code from vendor, vendor tends to change less, so you can take more advantage of cache

Upvotes: 1

Josh Beam
Josh Beam

Reputation: 19792

There is no one proper size. The less bytes the better, but it depends on your code base it order to determine how small you can realistically get. The bigger the file, the greater network latency retrieving the files (so, this will impact the user more negatively). So if you had to come up with a general "rule", the smaller the better.

Upvotes: 1

Related Questions