Read my book

I wrote books about Webpack and React. Check them out!

Friday, February 11, 2011

How to Structure Your Application Using RequireJS?

I've been using RequireJS, a module loading library for JavaScript, for the past few months. Since I started I've learned quite a bit about it. It was a bit rough at first but forms a solid part of my toolkit now. I really find it hard to imagine JS development without it. It's like driving a Porsche without proper wheels... Just as frustrating. :)

Besides providing nifty module syntax it allows you to optimize your project easily. In fact this is something you get for free once you set up your project certain way. Highly useful!

Even though the project documentation is quite vast, it's pretty easy for a beginner to get lost in the detail. In this post I'm going to show you how to structure your application using RequireJS. It's not a "be all and end all" kind of solution. Consider it more as a starting point that you'll need to adapt to suit your needs.

Before getting into actual application structure I'm going to cover some core concepts briefly.