Require JS

2,396 views
2,184 views

Published on

Introduction to RequireJS

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,396
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
0
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Require JS

  1. 1. RequireJS <ul><li>What is it? </li></ul><ul><li>When to use it? </li></ul>by B.Shankar
  2. 2. What is it? <ul><li>A module loading library for Java Script </li></ul>by B.Shankar
  3. 3. When to use it? <ul><li>When you needed to load multiple JavaScript files into an application </li></ul><ul><li>Use RequireJS for Asynchronous Script Loading And JavaScript Dependency Management </li></ul>by B.Shankar
  4. 4. What it does? <ul><li>allows for asynchronous JavaScript loading and dependency management </li></ul><ul><li>uses a modular approach to dependency definitions. </li></ul>by B.Shankar
  5. 5. It includes? <ul><li>optimization and &quot;build&quot; tools for deployment </li></ul>by B.Shankar
  6. 6. <ul><li><!-- </li></ul><ul><li>Load the RequireJS library; the &quot;data-main&quot; attribute </li></ul><ul><li>will tell the RequireJS library which JavaScript file to </li></ul><ul><li>load (main.js) after itself has loaded. </li></ul><ul><li>--> </li></ul><ul><li><script </li></ul><ul><li>type=&quot;text/javascript&quot; </li></ul><ul><li>src=&quot;./require.js&quot; </li></ul><ul><li>data-main=&quot;./main&quot;> </li></ul><ul><li></script> </li></ul>Load it and then define the initial JavaScript file. by B.Shankar
  7. 7. main.js <ul><li>require( </li></ul><ul><li>[ </li></ul><ul><li>&quot;jquery-1.6.4.js&quot;, </li></ul><ul><li>&quot;friend&quot;, </li></ul><ul><li>&quot;pet&quot;, </li></ul><ul><li>&quot;cat-lover&quot; </li></ul><ul><li>], </li></ul><ul><li>function( _jquery_, Friend, Pet, CatLover ) { </li></ul><ul><li>} </li></ul>by B.Shankar
  8. 8. Require([ ], { }) <ul><li>require() executes code once the given dependencies have been loaded. </li></ul>by B.Shankar
  9. 9. friend.js <ul><li>define( </li></ul><ul><li>[ </li></ul><ul><li>&quot;jquery-1.6.4.js&quot; </li></ul><ul><li>], </li></ul><ul><li>function( _jquery_ ){ </li></ul><ul><li>} </li></ul>by B.Shankar
  10. 10. Define([ ], { }) <ul><li>When you define a RequireJS module, you use the define() function. </li></ul>by B.Shankar

×