Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS - one huge file or many small files? - where to draw a line?

Tags:

javascript

Is there a good rule of thumb as to how big (in size) a JS file should be - that if it grows bigger than this it's good idea to split it into smaller files?

like image 825
RubyDosa Avatar asked Mar 03 '11 13:03

RubyDosa


People also ask

What is better to load one complete JavaScript file on all pages or separate files based on different pages?

It is best to keep separate files or include all files in one file Javascript? To avoid multiple server requests, it is better to group all your JavaScript files into only one. If you're using C#.Net + ASP.Net, you can bundle your files — it is a very good way to compress your scripts.

What is considered a large JavaScript file?

URLs contain JavaScript files of size over 25 KB. The figure of 25KB is relatively arbitrary – there is no hard and fast rule as to what constitutes an JavaScript file that is 'too large'.


2 Answers

The same size as any other languages (never more than a few hundred lines), and the concat and minify at runtime (using the Closure compiler or the Yahoo libs or whatnot) is what we do.

like image 164
Marcus Frödin Avatar answered Oct 25 '22 16:10

Marcus Frödin


More files = More HTTP Requests = Slower website

like image 27
Marko Avatar answered Oct 25 '22 16:10

Marko