What is the recommended maximum amount of lines a JS document can have before it starts to lose performance?, i mean, At what number is it better to create a new document instead of keep coding in the same file and making it bigger and bigger?
-
4∞ lines of code, I believe. – Niet the Dark Absol Apr 07 '14 at 14:28
-
1How long is a piece of string? Dup; [One big javascript file or multiple smaller files?](http://stackoverflow.com/questions/15236767/one-big-javascript-file-or-multiple-smaller-files) – Alex K. Apr 07 '14 at 14:29
1 Answers
To my knowledge there is absolutely no reason why a big JavaScript file would be a performance hit. However here are a couple of things to consider:
First, big files are harder to work with. It's generally a good idea to break down your file into logical segments, and then combine them all together (plus minification) when they're used on the site. This is especially true when working with other people on a project, as it's easier to version individual files and you avoid the risk of overwriting each others' work (or at least significantly reduce it)
Second, a large script will have to download in its entirity before any of it can be run. This only makes a difference if you defer scripts (as you should), but it may be useful to put critically important scripts in an inline <script>
tag (minified, of course) so that the page at least renders. Then defer your big script and let it run whenever it has downloaded.
Hope this helps!

- 320,036
- 81
- 464
- 592
-
Thanks for your reply, but maybe i didnt explain myself clearly , i mean, in which point it is a better idea to start coding on another file, than making the main one bigger and bigger ?. 2500 lines ? 5000 lines? 10000 lines?. AT some point the weight and scale of the file starts to become a performance issue in which point is it ? – Franco Aguilera Apr 07 '14 at 15:05