Last Updated: August 26, 2016
·
2.937K
· stefanprodan

Introducing RequireJS for ASP.NET MVC

Writing modular JavaScript is the first step in bringing the front-end development closer to the server-side OOP, for a C# programmer, the Module Pattern applied to JavaScript means that you can emulate the .NET class behavior by having public/private members and methods. With RequireJS you can go even further, by declaring a module you can specify dependencies to other modules, the same way as you do in a .NET project when you add references to other .NET components.

Before a module is loaded by the browser, RequireJS will look for the dependencies required by that module to function, it will fetch asynchronously from the server all the other modules needed and then will let the browser execute your module code. This technique can be easily understood if you think about how .NET Framework uses the JIT compiler to link assemblies, in .NET, a referenced .dll gets loaded when the first method is trying to access anything from the referenced assembly, in JavaScript, RequireJS loads all the referenced modules and executes them in the right order before the main module is executed. Further more, RequireJS can optimize the page load by combining all dependencies into a single minified js file.

The RequireJS for .NET project smoothly integrates the RequireJS framework with ASP.NET MVC on the server side using xml configuration files, action filter attributes, a base controller for inheritance and helper classes.

Read more on RequireJS.NET website