Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
36
rated 0 times [  40] [ 4]  / answers: 1 / hits: 15107  / 12 Years ago, sun, september 2, 2012, 12:00:00

This may be a dumb question for web guys. But I am a little confused over this. Now, I have an application where I am using a couple of Javascript files to perform different tasks. Now, I am using Javascript bundler to combine and minify all the files. So, at runtime there will be only one app.min.js file. Now, Requirejs is used to load modules or files at runtime. So, the question is if I already have all things in one file, then do I need requirejs? Or what is a use case scenario where I can use requirejs and/or bundler?



Please let me know if any further details are needed.


More From » requirejs

 Answers
28

This is a hotly contested issue among many proficient javascript developers. Many other languages have a compilation phase where the entire program is bundled up for deployment (JBoss's .WAR files come to mind). Programmers that come from more traditional backgrounds often favor this approach.



Javascript has seen such growth in recent years that it is difficult to chart exact best practices, but those that appreciate the more functional nature of Javascript often prefer the module loading approach (like require.js uses).



I wrote Frame.js which works much like require.js, so my bias is towards the module loader approach.



To answer your question directly, yes, it is one or the other.



Most that argue for packing your scripts into a single file believe it enables more compression and is thus more efficient. I believe the efficiency advantages of packaging are negligible in most cases because: (1) module load times are distributed over the entire session, (2) individual modules can be compressed to nearly the same percentage, (3) individual modules can be cached by the server and routers separately, and (4) loading scripts only when they are needed ultimately allows you load less code for some users and more code overall.



In the long run, if you can see an advantage to dynamic script loading use it. If not, bundle your scripts into a single file.


[#83289] Friday, August 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mira

Total Points: 460
Total Questions: 108
Total Answers: 99

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
mira questions
;