1

I hope this isn't too subjective, but this question definitely doesn't belong on SO...

I'm currently writing a large ASP.NET MVC 5 application and most views have their own javascript files as to be expected. What I'm having an issue with is determining is how to include the various javascript dependencies. Obviously, not every individual javascript file for each view necessarily requires all of the dependencies (with exception of jQuery and Bootstrap). I've been reading up on different methods of including the dependencies, and trying to compare their pros & cons to each other, but I'm still not sure which method would not only be best for performance, but for future extensibility, such as the ability to make changes/replace dependencies and adding additional modules/features. I don't believe there is a "right" answer to this question, but some direction would be helpful.

Here are the methods that I've been researching:

  1. Include the necessary dependencies in the scripts section for each view when they are needed. (This is what's done in the application's current state, but I believe it's a naive approach)
  2. Create a giant bundle for all dependancies a la this question (Probably not a good idea, see #3)
  3. Creating bundles for each combination of dependencies that the views require.
  4. Using AMD & requires.js to load javascript files dynamically. Potentially using RequiresJS.NET

I'm kind of leaning towards option 4, since it appears to meet my non-functional requirements, but to be honest I don't know much about that framework. Additionally, it kind of seems like I lose some of the ASP.NET magic if I go this route such as automatic bundling/minification, which is very helpful during debugging and performance when building for either debug or release. Whereas with option #3 I don't lose those features, but it doesn't seem nearly as manageable in the future.

Is one of these methods significantly better than the others, and/or is there an option that I haven't come across yet that would be even better in this situation?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.