Search code examples
javascriptbuildrequirejsamd

Why should I use require.js if I still concenate all files on build?


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?


Solution

  • 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).