Next I tried to separate the code into multiple script files that were more logically organized. Unfortunately this led me to even more issues:
- How could I separate out different layers of the application and make sure that these layers could communicate effectively?
- Why were these files so difficult to test?
I was really struggling with this design issue until I discovered AMD and began using Require.js.
What is Require.js?
Why should I use a module loader like Require.js?
Bundling and minifying with Require.js
ASP.NET MVC provides some really good out-of-the-box bundling and minification features. These work very well and also include built-in cache busting capability through the use of tokens based on file changes. However, remember that Require.js dynamically loads your module dependencies from the client via the AMD API. Require.js has its own server side optimization script named r.js.