SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
Dependency Management
    with RequireJS
      http://requirejs.org/
Who ?
Julien Cabanès
Front End Developper
mail : julien@zeeagency.com
twitter : @JulienCabanes
github : github.com/ZeeAgency
What are we talkin’ about?

• RequireJS.org : Script Module Loader
• Browsers && Node && Rhino
• Dependencies
• Global Pollution
• Optimization
Context
Libs of choice

  jQuery


 Backbone
Context
Libs of choice   Plugins

  jQuery


 Backbone
Context
Libs of choice   Plugins   Your Code

  jQuery


 Backbone
Bad Context
Libs of choice     Plugins   Your Code

  jQuery


 Backbone
Good Context
Libs of choice   Plugins   Your Code

  jQuery


 Backbone
Dependencies
Libs of choice     Plugins   Your Code

  jQuery


 Backbone
Solution ?
<script   src="jquery.min.js"></script>
<script   src="backbone.min.js"></script>
...
<script   src="jquery.plugin.js"></script>
<script   src="jquery.plugin.js"></script>
...
<script   src="my-code.js"></script>
<script   src="my-code.js"></script>
<script   src="my-code.js"></script>
<script   src="my-code.js"></script>
<script   src="my-code.js"></script>
...
Async Solution ?
<script src="LAB.js"></script>
<script type="text/javascript">
$LAB
	 .script('jquery.min.js')
	 .script('backbone.min.js')
	 ...
	 .script('jquery.plugin.js')
	 .script('jquery.plugin.js')
	 .script('jquery.plugin.js')
	 ...
	 .script('my-code.js')
	 .script('my-code.js')
	 .script('my-code.js');
</script>
Namespace ?
var MyNamespace = {};

MyNamespace.Config = {…};

MyNamespace.Product = function() {…};

MyNamespace.Video = function() {…};

MyNamespace.Audio = function() {…};

MyNamespace.Mail = function() {…};
AMD

Not your CPU...
Asynchronous Module Definition

https://github.com/amdjs/amdjs-api/wiki/AMD
define()
API
define(id?, dependencies?, factory);


Usage
define('My-Module', ['Another-Module'],
	 function(AnotherModule) {
	 	 // Do Something

	 }
);
Example

// App/Conf.js
define(function() {
	 return {
	 	 path: '...',
	 	 debug: true,
	 	 ...
	 };
});
Example

// App/Conf.js
define(function() {
	 return {
	 	 path: '...',
	 	 debug: true,
	 	 ...
	 };
});
Example
// App/Controller/Product.js
define(['App/Conf', 'App/Models/Product', 'App/Views/Product'],
function(Conf, Model, View) {
	
	   // Locale & Private Vars !!!
	   var myPrivateVar = {...};
	
	   // API
	   return {
	   	 show: function(productId) {
	   	
	   	 	 console.log(Conf.path);
	   	 	
	   	 	 var productView = new View();
	   	 	 productView.setModel(Model.getById(productId));
	   	 	
	   	 	 return productView.render();
	   	 },
       ...
	   };
});
Example
// App/Controller/Product.js
define(['App/Conf', 'App/Models/Product', 'App/Views/Product'],
function(Conf, Model, View) {
	
	   // Locale & Private Vars !!!
	   var myPrivateVar = {...};
	
	   // API
	   return {
	   	 show: function(productId) {
	   	
	   	 	 console.log(Conf.path);
	   	 	
	   	 	 var productView = new View();
	   	 	 productView.setModel(Model.getById(productId));
	   	 	
	   	 	 return productView.render();
	   	 },
       ...
	   };
});
Example
// App/Controller/Product.js
define(['App/Conf', 'App/Models/Product', 'App/Views/Product'],
function(Conf, Model, View) {
	
	   // Locale & Private Vars !!!
	   var myPrivateVar = {...};
	
	   // API
	   return {
	   	 show: function(productId) {
	   	
	   	 	 console.log(Conf.path);
	   	 	
	   	 	 var productView = new View();
	   	 	 productView.setModel(Model.getById(productId));
	   	 	
	   	 	 return productView.render();
	   	 },
       ...
	   };
});
Example
// App/Controller/Product.js
define(['App/Conf', 'App/Models/Product', 'App/Views/Product'],
function(Conf, Model, View) {
	
	   // Locale & Private Vars !!!
	   var myPrivateVar = {...};
	
	   // API
	   return {
	   	 show: function(productId) {
	   	
	   	 	 console.log(Conf.path);
	   	 	
	   	 	 var productView = new View();
	   	 	 productView.setModel(Model.getById(productId));
	   	 	
	   	 	 return productView.render();
	   	 },
       ...
	   };
});
Example
// App/Controller/Product.js
define(['App/Conf', 'App/Models/Product', 'App/Views/Product'],
function(Conf, Model, View) {
	
	   // Locale & Private Vars !!!
	   var myPrivateVar = {...};
	
	   // API
	   return {
	   	 show: function(productId) {
	   	
	   	 	 console.log(Conf.path);
	   	 	
	   	 	 var productView = new View();
	   	 	 productView.setModel(Model.getById(productId));
	   	 	
	   	 	 return productView.render();
	   	 },
       ...
	   };
});
Scope vs. Global Pollution
// App/Controller/Product.js
define(['App/Conf', 'App/Models/Product', 'App/Views/Product'],
function(Conf, Model, View) {
	
	   // Locale & Private Vars !!!
	   var myPrivateVar = {...};
	
	   // API
	   return {
	   	 show: function(productId) {
	   	
	   	 	 console.log(Conf.path);
	   	 	
	   	 	 var productView = new View();
	   	 	 productView.setModel(Model.getById(productId));
	   	 	
	   	 	 return productView.render();
	   	 },
...
	   };
});
Plugins Example
// App/View/Product.js
define([
	   'order!FirstModule',
	   'order!SecondModule',
    'i18n!fr/some-i18n-bundle',
	   'text!some-text-file.txt',
    'cs!some-coffee',
	   'tpl!App/View/Product.tpl'
], function(First, Second, bundle, text, coffee, productTpl) {
	
	   // API
	   return Backbone.View.extend({
	
	   	 render: function() {
	   	 	 return productTpl({
	   	 	 	 model: this.model.toJSON()
	   	 	 });
	   	 }
	   });
});
Order Plugin
// App/View/Product.js
define([
    	'order!FirstModule',            // Keep execution order
	    'order!SecondModule',           // requirejs.org/docs/api.html#order
     'i18n!fr/some-i18n-bundle',
	    'text!some-text-file.txt',
     'cs!some-coffee',
	    'tpl!App/View/Product.tpl'
], function(First, Second, bundle, text, coffee, productTpl) {
	
	    // API
	    return Backbone.View.extend({
	
	    	 render: function() {
	    	 	 return productTpl({
	    	 	 	 model: this.model.toJSON()
	    	 	 });
	    	 }
	    });
});
i18n Plugin
// App/View/Product.js
define([
    	'order!FirstModule',
	    'order!SecondModule',
     'i18n!fr/some-i18n-bundle',     // Load i18n bundle
	    'text!some-text-file.txt',      // requirejs.org/docs/api.html#i18n
     'cs!some-coffee',
	    'tpl!App/View/Product.tpl'
], function(First, Second, bundle, text, coffee, productTpl) {
	
	    // API
	    return Backbone.View.extend({
	
	    	 render: function() {
	    	 	 return productTpl({
	    	 	 	 model: this.model.toJSON()
	    	 	 });
	    	 }
	    });
});
Text Plugin
// App/View/Product.js
define([
    	'order!FirstModule',
	    'order!SecondModule',
     'i18n!fr/some-i18n-bundle',
	    'text!some-text-file.txt',      // Guess what ?
     'cs!some-coffee',               // requirejs.org/docs/api.html#text
	    'tpl!App/View/Product.tpl'
], function(First, Second, bundle, text, coffee, productTpl) {
	
	    // API
	    return Backbone.View.extend({
	
	    	 render: function() {
	    	 	 return productTpl({
	    	 	 	 model: this.model.toJSON()
	    	 	 });
	    	 }
	    });
});
CoffeeScript Plugin
// App/View/Product.js
define([
    	'order!FirstModule',
	    'order!SecondModule',
     'i18n!fr/some-i18n-bundle',
	    'text!some-text-file.txt',
     'cs!some-coffee',               // returns compiled CoffeeScript !
	    'tpl!App/View/Product.tpl'      // github.com/jrburke/require-cs
], function(First, Second, bundle, text, coffee, productTpl) {
	
	    // API
	    return Backbone.View.extend({
	
	    	 render: function() {
	    	 	 return productTpl({
	    	 	 	 model: this.model.toJSON()
	    	 	 });
	    	 }
	    });
});
Template Plugin
// App/View/Product.js
define([
    	'order!FirstModule',
	    'order!SecondModule',
     'i18n!fr/some-i18n-bundle',
	    'text!some-text-file.txt',      // My Favorite Plugin ! (mine...)
     'cs!some-coffee',               // Returns a compiled template !
	    'tpl!App/View/Product.tpl'      // github.com/ZeeAgency/requirejs-tpl
], function(First, Second, bundle, text, coffee, productTpl) {
	
	    // API
	    return Backbone.View.extend({
	
	    	 render: function() {
	    	 	 return productTpl({
	    	 	 	 model: this.model.toJSON()
	    	 	 });
	    	 }
	    });
});
Optimization



node r.js -o name=bootstrap out=built.js baseUrl=js



          http://requirejs.org/docs/optimization.html
Remember ?
Libs of choice    Plugins   Your Code

  jQuery


 Backbone
Optimized !
Libs of choice   Ready for Production

  jQuery
Optimized !
Libs of choice   Ready for Production

  jQuery




                   CoffeeScript ?
Optimized !
Libs of choice   Ready for Production

  jQuery




                   CoffeeScript ?
                    Templates ?
Optimized !
Libs of choice       Ready for Production

  jQuery




                     CoffeeScript ?
                      Templates ?
                  Compiled & Minified
           so browser doesn’t need to...
Optimized !
Libs of choice    Ready for Production

  jQuery




                    CoffeeScript ?
                     Templates ?
                 Compiled & Minified
Thx !

Weitere ähnliche Inhalte

Was ist angesagt?

Refactoring JavaScript Applications
Refactoring JavaScript ApplicationsRefactoring JavaScript Applications
Refactoring JavaScript ApplicationsJovan Vidić
 
CFUGbe talk about Angular JS
CFUGbe talk about Angular JSCFUGbe talk about Angular JS
CFUGbe talk about Angular JSAlwyn Wymeersch
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework Sakthi Bro
 
Arquitetura de Front-end em Aplicações de Larga Escala
Arquitetura de Front-end em Aplicações de Larga EscalaArquitetura de Front-end em Aplicações de Larga Escala
Arquitetura de Front-end em Aplicações de Larga EscalaEduardo Shiota Yasuda
 
Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator Alessio Ricco
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Confneal_kemp
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Fwdays
 
Intro to AngularJS
Intro to AngularJSIntro to AngularJS
Intro to AngularJSAaronius
 
An introduction to Ember.js
An introduction to Ember.jsAn introduction to Ember.js
An introduction to Ember.jscodeofficer
 
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
How React Native, Appium and me made each other shine @Frontmania 16-11-2018How React Native, Appium and me made each other shine @Frontmania 16-11-2018
How React Native, Appium and me made each other shine @Frontmania 16-11-2018Wim Selles
 
Architecture, Auth, and Routing with uiRouter
Architecture, Auth, and Routing with uiRouterArchitecture, Auth, and Routing with uiRouter
Architecture, Auth, and Routing with uiRouterChristopher Caplinger
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - IntroductionSagar Acharya
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.jsJay Phelps
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular componentsNir Kaufman
 
Testing C# and ASP.net using Ruby
Testing C# and ASP.net using RubyTesting C# and ASP.net using Ruby
Testing C# and ASP.net using RubyBen Hall
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceParashuram N
 

Was ist angesagt? (20)

Refactoring JavaScript Applications
Refactoring JavaScript ApplicationsRefactoring JavaScript Applications
Refactoring JavaScript Applications
 
CFUGbe talk about Angular JS
CFUGbe talk about Angular JSCFUGbe talk about Angular JS
CFUGbe talk about Angular JS
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
 
Modular and Event-Driven JavaScript
Modular and Event-Driven JavaScriptModular and Event-Driven JavaScript
Modular and Event-Driven JavaScript
 
Arquitetura de Front-end em Aplicações de Larga Escala
Arquitetura de Front-end em Aplicações de Larga EscalaArquitetura de Front-end em Aplicações de Larga Escala
Arquitetura de Front-end em Aplicações de Larga Escala
 
Creating Alloy Widgets
Creating Alloy WidgetsCreating Alloy Widgets
Creating Alloy Widgets
 
Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Conf
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
 
Intro to AngularJS
Intro to AngularJSIntro to AngularJS
Intro to AngularJS
 
An introduction to Ember.js
An introduction to Ember.jsAn introduction to Ember.js
An introduction to Ember.js
 
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
How React Native, Appium and me made each other shine @Frontmania 16-11-2018How React Native, Appium and me made each other shine @Frontmania 16-11-2018
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
 
Architecture, Auth, and Routing with uiRouter
Architecture, Auth, and Routing with uiRouterArchitecture, Auth, and Routing with uiRouter
Architecture, Auth, and Routing with uiRouter
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
 
Intro to Ember.JS 2016
Intro to Ember.JS 2016Intro to Ember.JS 2016
Intro to Ember.JS 2016
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.js
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular components
 
Testing C# and ASP.net using Ruby
Testing C# and ASP.net using RubyTesting C# and ASP.net using Ruby
Testing C# and ASP.net using Ruby
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
 

Ähnlich wie ParisJS #10 : RequireJS

A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJSGregor Woiwode
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Spike Brehm
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Api development with rails
Api development with railsApi development with rails
Api development with railsEdwin Cruz
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSAntonio Peric-Mazar
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - ServicesNir Kaufman
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSGunnar Hillert
 
A Story about AngularJS modularization development
A Story about AngularJS modularization developmentA Story about AngularJS modularization development
A Story about AngularJS modularization developmentJohannes Weber
 
Telerik AppBuilder Presentation for TelerikNEXT Conference
Telerik AppBuilder Presentation for TelerikNEXT ConferenceTelerik AppBuilder Presentation for TelerikNEXT Conference
Telerik AppBuilder Presentation for TelerikNEXT ConferenceJen Looper
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersOswald Campesato
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverSpike Brehm
 
Python Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - AppenginePython Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - AppenginePython Ireland
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Eliran Eliassy
 
SharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSébastien Levert
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.jsMatthew Beale
 
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...Wim Selles
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java DevelopersYakov Fain
 
Drupal 8, Where Did the Code Go? From Info Hook to Plugin
Drupal 8, Where Did the Code Go? From Info Hook to PluginDrupal 8, Where Did the Code Go? From Info Hook to Plugin
Drupal 8, Where Did the Code Go? From Info Hook to PluginAcquia
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdevFrank Rousseau
 

Ähnlich wie ParisJS #10 : RequireJS (20)

A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Api development with rails
Api development with railsApi development with rails
Api development with rails
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 
A Story about AngularJS modularization development
A Story about AngularJS modularization developmentA Story about AngularJS modularization development
A Story about AngularJS modularization development
 
Telerik AppBuilder Presentation for TelerikNEXT Conference
Telerik AppBuilder Presentation for TelerikNEXT ConferenceTelerik AppBuilder Presentation for TelerikNEXT Conference
Telerik AppBuilder Presentation for TelerikNEXT Conference
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and server
 
Python Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - AppenginePython Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - Appengine
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
SharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure Functions
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.js
 
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
 
Drupal 8, Where Did the Code Go? From Info Hook to Plugin
Drupal 8, Where Did the Code Go? From Info Hook to PluginDrupal 8, Where Did the Code Go? From Info Hook to Plugin
Drupal 8, Where Did the Code Go? From Info Hook to Plugin
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
 

Kürzlich hochgeladen

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Kürzlich hochgeladen (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

ParisJS #10 : RequireJS

  • 1. Dependency Management with RequireJS http://requirejs.org/
  • 2. Who ? Julien Cabanès Front End Developper mail : julien@zeeagency.com twitter : @JulienCabanes github : github.com/ZeeAgency
  • 3. What are we talkin’ about? • RequireJS.org : Script Module Loader • Browsers && Node && Rhino • Dependencies • Global Pollution • Optimization
  • 4. Context Libs of choice jQuery Backbone
  • 5. Context Libs of choice Plugins jQuery Backbone
  • 6. Context Libs of choice Plugins Your Code jQuery Backbone
  • 7. Bad Context Libs of choice Plugins Your Code jQuery Backbone
  • 8. Good Context Libs of choice Plugins Your Code jQuery Backbone
  • 9. Dependencies Libs of choice Plugins Your Code jQuery Backbone
  • 10. Solution ? <script src="jquery.min.js"></script> <script src="backbone.min.js"></script> ... <script src="jquery.plugin.js"></script> <script src="jquery.plugin.js"></script> ... <script src="my-code.js"></script> <script src="my-code.js"></script> <script src="my-code.js"></script> <script src="my-code.js"></script> <script src="my-code.js"></script> ...
  • 11. Async Solution ? <script src="LAB.js"></script> <script type="text/javascript"> $LAB .script('jquery.min.js') .script('backbone.min.js') ... .script('jquery.plugin.js') .script('jquery.plugin.js') .script('jquery.plugin.js') ... .script('my-code.js') .script('my-code.js') .script('my-code.js'); </script>
  • 12. Namespace ? var MyNamespace = {}; MyNamespace.Config = {…}; MyNamespace.Product = function() {…}; MyNamespace.Video = function() {…}; MyNamespace.Audio = function() {…}; MyNamespace.Mail = function() {…};
  • 13. AMD Not your CPU... Asynchronous Module Definition https://github.com/amdjs/amdjs-api/wiki/AMD
  • 14. define() API define(id?, dependencies?, factory); Usage define('My-Module', ['Another-Module'], function(AnotherModule) { // Do Something } );
  • 15. Example // App/Conf.js define(function() { return { path: '...', debug: true, ... }; });
  • 16. Example // App/Conf.js define(function() { return { path: '...', debug: true, ... }; });
  • 17. Example // App/Controller/Product.js define(['App/Conf', 'App/Models/Product', 'App/Views/Product'], function(Conf, Model, View) { // Locale & Private Vars !!! var myPrivateVar = {...}; // API return { show: function(productId) { console.log(Conf.path); var productView = new View(); productView.setModel(Model.getById(productId)); return productView.render(); }, ... }; });
  • 18. Example // App/Controller/Product.js define(['App/Conf', 'App/Models/Product', 'App/Views/Product'], function(Conf, Model, View) { // Locale & Private Vars !!! var myPrivateVar = {...}; // API return { show: function(productId) { console.log(Conf.path); var productView = new View(); productView.setModel(Model.getById(productId)); return productView.render(); }, ... }; });
  • 19. Example // App/Controller/Product.js define(['App/Conf', 'App/Models/Product', 'App/Views/Product'], function(Conf, Model, View) { // Locale & Private Vars !!! var myPrivateVar = {...}; // API return { show: function(productId) { console.log(Conf.path); var productView = new View(); productView.setModel(Model.getById(productId)); return productView.render(); }, ... }; });
  • 20. Example // App/Controller/Product.js define(['App/Conf', 'App/Models/Product', 'App/Views/Product'], function(Conf, Model, View) { // Locale & Private Vars !!! var myPrivateVar = {...}; // API return { show: function(productId) { console.log(Conf.path); var productView = new View(); productView.setModel(Model.getById(productId)); return productView.render(); }, ... }; });
  • 21. Example // App/Controller/Product.js define(['App/Conf', 'App/Models/Product', 'App/Views/Product'], function(Conf, Model, View) { // Locale & Private Vars !!! var myPrivateVar = {...}; // API return { show: function(productId) { console.log(Conf.path); var productView = new View(); productView.setModel(Model.getById(productId)); return productView.render(); }, ... }; });
  • 22. Scope vs. Global Pollution // App/Controller/Product.js define(['App/Conf', 'App/Models/Product', 'App/Views/Product'], function(Conf, Model, View) { // Locale & Private Vars !!! var myPrivateVar = {...}; // API return { show: function(productId) { console.log(Conf.path); var productView = new View(); productView.setModel(Model.getById(productId)); return productView.render(); }, ... }; });
  • 23. Plugins Example // App/View/Product.js define([ 'order!FirstModule', 'order!SecondModule', 'i18n!fr/some-i18n-bundle', 'text!some-text-file.txt', 'cs!some-coffee', 'tpl!App/View/Product.tpl' ], function(First, Second, bundle, text, coffee, productTpl) { // API return Backbone.View.extend({ render: function() { return productTpl({ model: this.model.toJSON() }); } }); });
  • 24. Order Plugin // App/View/Product.js define([ 'order!FirstModule', // Keep execution order 'order!SecondModule', // requirejs.org/docs/api.html#order 'i18n!fr/some-i18n-bundle', 'text!some-text-file.txt', 'cs!some-coffee', 'tpl!App/View/Product.tpl' ], function(First, Second, bundle, text, coffee, productTpl) { // API return Backbone.View.extend({ render: function() { return productTpl({ model: this.model.toJSON() }); } }); });
  • 25. i18n Plugin // App/View/Product.js define([ 'order!FirstModule', 'order!SecondModule', 'i18n!fr/some-i18n-bundle', // Load i18n bundle 'text!some-text-file.txt', // requirejs.org/docs/api.html#i18n 'cs!some-coffee', 'tpl!App/View/Product.tpl' ], function(First, Second, bundle, text, coffee, productTpl) { // API return Backbone.View.extend({ render: function() { return productTpl({ model: this.model.toJSON() }); } }); });
  • 26. Text Plugin // App/View/Product.js define([ 'order!FirstModule', 'order!SecondModule', 'i18n!fr/some-i18n-bundle', 'text!some-text-file.txt', // Guess what ? 'cs!some-coffee', // requirejs.org/docs/api.html#text 'tpl!App/View/Product.tpl' ], function(First, Second, bundle, text, coffee, productTpl) { // API return Backbone.View.extend({ render: function() { return productTpl({ model: this.model.toJSON() }); } }); });
  • 27. CoffeeScript Plugin // App/View/Product.js define([ 'order!FirstModule', 'order!SecondModule', 'i18n!fr/some-i18n-bundle', 'text!some-text-file.txt', 'cs!some-coffee', // returns compiled CoffeeScript ! 'tpl!App/View/Product.tpl' // github.com/jrburke/require-cs ], function(First, Second, bundle, text, coffee, productTpl) { // API return Backbone.View.extend({ render: function() { return productTpl({ model: this.model.toJSON() }); } }); });
  • 28. Template Plugin // App/View/Product.js define([ 'order!FirstModule', 'order!SecondModule', 'i18n!fr/some-i18n-bundle', 'text!some-text-file.txt', // My Favorite Plugin ! (mine...) 'cs!some-coffee', // Returns a compiled template ! 'tpl!App/View/Product.tpl' // github.com/ZeeAgency/requirejs-tpl ], function(First, Second, bundle, text, coffee, productTpl) { // API return Backbone.View.extend({ render: function() { return productTpl({ model: this.model.toJSON() }); } }); });
  • 29. Optimization node r.js -o name=bootstrap out=built.js baseUrl=js http://requirejs.org/docs/optimization.html
  • 30. Remember ? Libs of choice Plugins Your Code jQuery Backbone
  • 31. Optimized ! Libs of choice Ready for Production jQuery
  • 32. Optimized ! Libs of choice Ready for Production jQuery CoffeeScript ?
  • 33. Optimized ! Libs of choice Ready for Production jQuery CoffeeScript ? Templates ?
  • 34. Optimized ! Libs of choice Ready for Production jQuery CoffeeScript ? Templates ? Compiled & Minified so browser doesn’t need to...
  • 35. Optimized ! Libs of choice Ready for Production jQuery CoffeeScript ? Templates ? Compiled & Minified
  • 36. Thx !