O'Reilly logo

Backbone.js Cookbook by Vadim Mirgorod

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Organizing a project structure with Require.js

In this recipe, we are going to use the Asynchronous Module Definition (AMD) technique that is implemented in Require.js, the JavaScript library, which helps to bring more order into your project. It allows you to define and load JavaScript modules dynamically from other parts of your code in a way similar to that in PHP using the include command. It can also optimize and uglify the JavaScript files so that they are loaded and executed faster.

We will take the Social Mobile Application example from the previous recipe and will refactor it using the Require.js library.

The directory structure of our app will look like the following structure:

  • css/
    • main.css
  • js/
    • collection/
    • post.js
  • model/
    • post.js
  • view/
    • about-page.js ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required