Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just started using requirejs and I love it. I have one concern though. I've been compressing all my js files into one single file. Even with requirejs optimizer, I need to load module files from the server time to time and I'm concerned with it.

Performance and user experience wise, which one is better?

share|improve this question
I am not sure I understand your concerns. With the optimizer you can get away with just two files: requireJS itself and the optimized file. Is it a problem loading two files instead of one? – Andrea Jun 29 '12 at 20:18
up vote 4 down vote accepted

Performance and user experience wise, which one is better?

A single compressed file.

It is a single connection, so the browser is free to download other assets.

It is compressed, so it takes less time to transfer to the browser.

Both mean that the page and the javascript run faster - this is better user experience and better performance.

Win win.

share|improve this answer
@ooded // but the problem of compressing all the files is that the result file might contain codes that users might never hit. What do you think about it? – Moon Jun 29 '12 at 19:44
@Moon - Yes, that's a risk. Some minification frameworks let you tailor which files go with which page, to remove this issue. – Oded Jun 29 '12 at 19:46

The reason to break up your .js files is to reduce the initial load time to be as small as possible. the first load is the most critical because it generally determines if a user will bother with exploring your site further or they perceive it as slow. If that first load is important to you it may be worth taking out unneeded files for your homepage and checking if it noticeably changes that initial load, otherwise Oded's advice is solid.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.