It sure makes a lot of sense to write modular, independent testable code - especially for big projects.
But what difference does using require.js
/amd
make in a big project where I still need to concenate & minify my project on build?
RequireJS is a JavaScript library and file loader which manages the dependencies between JavaScript files and in modular programming. It also helps to improve the speed and quality of the code.
It is best to keep separate files or include all files in one file Javascript? To avoid multiple server requests, it is better to group all your JavaScript files into only one. If you're using C#.Net + ASP.Net, you can bundle your files — it is a very good way to compress your scripts.
You can write your JS in separate files, but when it comes to deploying, it's more efficient to minify them all into a single file. For each script you load in your browser, you make a round-trip to the server, so it makes sense to minimize those.
It separates HTML and code. It makes HTML and JavaScript easier to read and maintain.
I would like to preface my response with saying that I do think Require.JS is an utterly useless framework. It over-complicates a fairly simple concept.
That being said, dependency loading is VERY useful when it comes to writing platform independent code.
For example, say you wanted to develop a web application that you can also port into Apache Cordova for mobile apps and into AppJS for desktop apps. You wouldn't want to rewrite all of your business logic, so it makes sense to build a bootstrap that loads dependencies dynamically to adapt the software to multiple architectures. That way you only have one product, which is able to run on a variety of platforms. Add in the usage of NodeJS for server side script and you can not only write front end software, but back end with the exact same code.
Modularity helps a lot with cross-platform projects, but as I said: Require.JS really isn't that useful. I have found it to be overly complicated. Instead, I just use an object built around jQuery's getScript function that contains a registry of all loaded packages so that a dev doesn't try to load a package that has already been loaded (larger projects).
There are a number of advantages to require.js, such as:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With