Main Content

Writing Modular JavaScript with AMD and RequireJS

About the Talk

April 28, 2013 11:00 AM

College of Lake County, Grayslake, IL

College of Lake County, Grayslake, IL

Lets not kid ourselves, doing application-scale development with JavaScript is hard. We dont get the clean, organized, module support in JS like we do in the more traditional programming languages--not easily anyways. What do we mean when we say "Modular JavaScript"? What we are talking about is componentizing our code into re-usable blocks of code. Splitting up our code this way allows us to create large applications that are built using loosely-coupled modules, which make developing, testing, and maintenance easier. The challenge in achieving this in JavaScript arises in resolving dependencies in our modules, we have to ensure other script files and libraries are imported through script tags in out html file before our modules are loaded. With large applications, this becomes a difficult thing to maintain, and we typically end up many source files being downloaded synchronously when we hit the first page of our application.

AMD (Asynchronous Module Definition) is a specification for defining modules where both the module and dependencies can be asynchronously loaded, giving us the advantage of asynchronous loading of our scripts, along with the flexibility of a loosely-coupled system. Fortunately, implementing AMD in our JavaScript is easy with the help of RequireJS. This talk will cover the basics of AMD and how to structure our JS on the file system to make our code easier to work with. We will also walk through how to design a custom module that depends on jQuery and wire it up with RequireJS. Finally, we will put it all together in a fully functional web app.

Ratings and Recommendations

This Talk hasn't been rated yet. Sign In to rate Talks.

comments powered by Disqus