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
main-page.js
post-add-page.js
post-delete-dialog.js
post-details-page.js
post-list-page.js
settings-page.js
app-config.js
app.js
jqm-config.js
router.js
template-loader.js
lib/
glyphish
/ios_inspired/
jquery
.mobile/
backbone-mongodb.js
backbone.js
jquery.js
require...