SlideShare ist ein Scribd-Unternehmen logo
1 von 64
Sexy.js
Dave Furfero
UI Engineer, MLB.com
Sexy.js
          Slideshow
 http://www.slideshare.net/furf
Sexy.js
A lightweight JavaScript library which provides enhanced
Sequential Ajax (Sajax) functionality and a sleek facade to
jQuery’s native Ajax methods.
Sexy.js
 Facilitates combination and manipulation of data from
 multiple sources
 Speeds loading of scripts, stylesheets, and data using
 parallel asynchronous HTTP requests
Ugly.js
$.getJSON('articles.json', function (articles) {
 $.getJSON('comments.json', function (comments) {
   $.getJSON('ratings.json', function (ratings) {

     $.each(comments, function (i, comment) {
       articles[comment.articleId].comments.push(comment);
     });

     $.each(ratings, function (i, rating) {
       articles[rating.articleId].rating = rating;
     });

    });
  });
});
Sexy.js
Sexy
 .json('articles.json')

 .json('comments.json', function (comments, status, articles) {
   $.each(comments, function (i, comment) {
     articles[comment.articleId].comments.push(comment);
   });
   return articles;
 })

 .json('ratings.json', function (ratings, status, articles) {
   $.each(ratings, function (i, rating) {
     articles[rating.articleId].rating = rating;
   });
 });
Ugly.js
<script src="/js/jquery.template.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/comments.css" type="text/css"/>

<script type="text/javascript">

$.get('comments.tpl', function (tpl) {
  $.getJSON('comments.json', function (data) {
    $.template(tpl, data).appendTo('#comments');
  });
});

</script>
Sexy.js
<script type="text/javascript">


Sexy
 .js('jquery.template.min.js')
 .css('comments.css')
 .text('comments.tpl')
 .json('comments.json', function (data, status, tpl) {
   $.template(tpl, data).appendTo('#comments');
 });

</script>
Sexy.js
Enhanced AJAX Functionality
Sequential Ajax (Sajax)
 Simultaneous request/sequential response Ajax
 Each successive callback receives the return value of
 the previous callback as an additional argument
Sexy.js
Expressive, Chainable API
Sexy.js API
Core Methods
    html (url, callback)
    json (url, callback)
   jsonp (url, callback)
  script/js (url, callback)
  style/css (url, callback)
    text (url, callback)
    xml (url, callback)
Sexy.js API
Core Methods
    html (url, callback)        html (settings)
    json (url, callback)        json (settings)
   jsonp (url, callback)       jsonp (settings)
  script/js (url, callback)   script/js (settings)
  style/css (url, callback)   style/css (settings)
    text (url, callback)        text (settings)
    xml (url, callback)         xml (settings)
Sexy.js API
callback (data, status, previous)


 Each callback receives three arguments:
   data
   status
   previous - the return value of the previous callback
   (considering a fourth) next or this
Sexy.js API
Additional Methods
 setup (settings)
     Similar to jQuery.ajaxSetup, but limited to
     subsequent calls of a Sexy instance
     Can be unset with setup()
 bundle (url1, url2, ..., callback)
     Client-side JavaScript packaging
     Multiple file, single <script> injection
     Sequence is preserved
Using Sexy.js
Sexy
Using Sexy.js
Loading JavaScripts
Sexy
 .js('jquery.template.min.js')
Using Sexy.js
Loading Stylesheets (local only)
Sexy
 .js('jquery.template.min.js')
 .css('comments.css')
Using Sexy.js
Loading Stylesheets (local only)
Sexy
 .js('jquery.template.min.js')
 .css('comments.css')
Using Sexy.js
Loading Data
Sexy
 .js('jquery.template.min.js')
 .css('comments.css')
 .text('comments.tpl', function (data) {
   return data;
 })
Using Sexy.js
Loading Data
Sexy
 .js('jquery.template.min.js')
 .css('comments.css')
 .text('comments.tpl', function (data) {
   return data;
 })
 .json('comments.json', function (data, status, tpl) {
   $.template(tpl, data).appendTo('#comments');
 });
Using Sexy.js
Custom Ajax Settings
Sexy
 .js('jquery.template.min.js')
 .css('comments.css')
 .text('comments.tpl', function (data) {
   return data;
 })
 .json({
   url: 'comments.json',
   data: {
     article_id: 123,
   },
   success: function (data, status, tpl) {
     $.template(tpl, data).appendTo('#comments');
   }
 });
Using Sexy.js
Passing Data with Callbacks
Sexy
 .js('jquery.template.min.js')
 .css('comments.css')
 .text('comments.tpl', function (data) {
   return data;
 })
 .json('comments.json?article_id=123', function (data, status, tpl) {
   $.template(tpl, data).appendTo('#comments');
 });
Using Sexy.js
Implicit Callbacks
Sexy
 .js('jquery.template.min.js')
 .css('comments.css')
 .text('comments.tpl', function (data) {
   return data;
 })
 .json('comments.json?article_id=123', function (data, status, tpl) {
   $.template(tpl, data).appendTo('#comments');
 });
Using Sexy.js
Implicit Callbacks
Sexy
 .js('jquery.template.min.js')
 .css('comments.css')
 .text('comments.tpl', function (data) {
   return data;
 })
 .json('comments.json?article_id=123', function (data, status, tpl) {
   $.template(tpl, data).appendTo('#comments');
 });
Using Sexy.js
Implicit Callbacks, Non-Data Types
Sexy
 .css('comments.css')
 .text('comments.tpl')
 .js('jquery.template.min.js', function (data, status, previous) {
   return previous;
 })
 .json('comments.json?article_id=123', function (data, status, tpl) {
   $.template(tpl, data).appendTo('#comments');
 });
Using Sexy.js
Implicit Callbacks, Non-Data Types
Sexy
 .css('comments.css')
 .text('comments.tpl')
 .js('jquery.template.min.js')
 .json('comments.json?article_id=123', function (data, status, tpl) {
   $.template(tpl, data).appendTo('#comments');
 });
Using Sexy.js
Configuring Sexy.js
Sexy
 .setup({ cache: true })
 .js('jquery.template.min.js')
 .css('comments.css')
 .text('comments.tpl')
 .json('comments.json', function (data, status, tpl) {
   $.template(tpl, data).appendTo('#comments');
 });
Using Sexy.js
Configuring Sexy.js
Sexy({
  cache: true
})
  .js('jquery.template.min.js')
  .css('comments.css')
  .text('comments.tpl')
  .json('comments.json', function (data, status, tpl) {
    $.template(tpl, data).appendTo('#comments');
  });
Using Sexy.js
Configuring Sexy.js
Sexy({
  cache: true
})
  .js('jquery.template.min.js')
  .css('comments.css')
  .text('comments.tpl')
  .setup({ cache: false })
  .json('comments.json', function (data, status, tpl) {
    $.template(tpl, data).appendTo('#comments');
  });
Using Sexy.js
Bundling JavaScripts
Sexy
 .bundle(
   '/js/bam.js',
   ‘/js/bam.datagrid.js',
   ‘/js/bam.stats.js',
   ‘/js/bam.stats.widget.js',
   ‘/js/bam.stats.widget.leagueSelector.js',
   ‘/js/bam.stats.app.js',
   ‘/js/bam.stats.app.sortablePlayerList.js'
 );
Using Sexy.js
Bundling JavaScripts
Sexy
 .bundle(
   '/js/bam.js',
   ‘/js/bam.datagrid.js',
   ‘/js/bam.stats.js',
   ‘/js/bam.stats.widget.js',
   ‘/js/bam.stats.widget.leagueSelector.js',
   ‘/js/bam.stats.app.js',
   ‘/js/bam.stats.app.sortablePlayerList.js',

   function (src) {
     SortablePlayerList.init();
   }
 );
Known Issues

Unable to detect error events for remote requests
  jsonp (remoteUrl)
  script (remoteUrl)
  style (remoteUrl)*
*style (remoteUrl) will actually fire success event even if
load was unsuccessful (ie. 404)
Sexy.js
 Enhanced Ajax functionality
 Expressive, chainable API
 Lightweight (1.3KB compressed)
Thanks!
Slideshow: http://www.slideshare.net/furf
URL: http://sexyjs.com
Demo: http://sexyjs.com/demos/comments
Download: http:github.com/furf/Sexy
Twitter: @sexyjs
E-mail: furf@furf.com
But wait... there’s more!
Sexy is the new Sexy
Sexy() == new Sexy()
function Sexy (cfg) {

    // Allow instantiation without new keyword

    if (!(this instanceof Sexy)) {
      return new Sexy(cfg);
    }

    this.cfgs = [];
    this.setup(cfg);
    this.evt = $(this);
}
Take it off... take it all off!
Sexy.method(url) == (new Sexy()).method(url)
// Alias instance methods as static methods of constructor

$.each(Sexy.prototype, function (name, method) {
  Sexy[name] = function () {
    return method.apply(new Sexy(), arguments);
  };
});

Weitere ähnliche Inhalte

Was ist angesagt?

Coffeescript - what's good
Coffeescript - what's goodCoffeescript - what's good
Coffeescript - what's good
JeongHun Byeon
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
Анатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to zАнатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to z
LEDC 2016
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New Evolution
Allan Huang
 
Django Class-based views (Slovenian)
Django Class-based views (Slovenian)Django Class-based views (Slovenian)
Django Class-based views (Slovenian)
Luka Zakrajšek
 
Testing your javascript code with jasmine
Testing your javascript code with jasmineTesting your javascript code with jasmine
Testing your javascript code with jasmine
Rubyc Slides
 
Building Smart Async Functions For Mobile
Building Smart Async Functions For MobileBuilding Smart Async Functions For Mobile
Building Smart Async Functions For Mobile
Glan Thomas
 

Was ist angesagt? (20)

JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
 
Coffeescript - what's good
Coffeescript - what's goodCoffeescript - what's good
Coffeescript - what's good
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 
Анатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to zАнатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to z
 
JQuery Presentation
JQuery PresentationJQuery Presentation
JQuery Presentation
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New Evolution
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
 
Django Class-based views (Slovenian)
Django Class-based views (Slovenian)Django Class-based views (Slovenian)
Django Class-based views (Slovenian)
 
Data20161007
Data20161007Data20161007
Data20161007
 
Testing your javascript code with jasmine
Testing your javascript code with jasmineTesting your javascript code with jasmine
Testing your javascript code with jasmine
 
The next step, part 2
The next step, part 2The next step, part 2
The next step, part 2
 
J query training
J query trainingJ query training
J query training
 
Jquery examples
Jquery examplesJquery examples
Jquery examples
 
Grails UI Primer
Grails UI PrimerGrails UI Primer
Grails UI Primer
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascript
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
 
Building Smart Async Functions For Mobile
Building Smart Async Functions For MobileBuilding Smart Async Functions For Mobile
Building Smart Async Functions For Mobile
 
Pengenalan blaast platform sdk
Pengenalan blaast platform sdkPengenalan blaast platform sdk
Pengenalan blaast platform sdk
 

Andere mochten auch

Cara menggunakan mailing list di office 2007
Cara menggunakan mailing list di office 2007Cara menggunakan mailing list di office 2007
Cara menggunakan mailing list di office 2007
teknisi7
 
Wound construction For Cataract Surgery
Wound construction For Cataract SurgeryWound construction For Cataract Surgery
Wound construction For Cataract Surgery
Devin Prabhakar
 
Cirugía de las cataratas
Cirugía de las cataratasCirugía de las cataratas
Cirugía de las cataratas
Vini Velas
 
Parejas de futbolistas
Parejas de futbolistasParejas de futbolistas
Parejas de futbolistas
las rozas
 
Indicaciones y evaluación preoperatoria de la catarata
Indicaciones y evaluación preoperatoria de la catarataIndicaciones y evaluación preoperatoria de la catarata
Indicaciones y evaluación preoperatoria de la catarata
DR. CARLOS Azañero
 

Andere mochten auch (20)

promocion 2009 oscar alfaro
promocion 2009 oscar alfaropromocion 2009 oscar alfaro
promocion 2009 oscar alfaro
 
Cara menggunakan mailing list di office 2007
Cara menggunakan mailing list di office 2007Cara menggunakan mailing list di office 2007
Cara menggunakan mailing list di office 2007
 
Wound construction For Cataract Surgery
Wound construction For Cataract SurgeryWound construction For Cataract Surgery
Wound construction For Cataract Surgery
 
Capacitación en salud ocular básica y sus derechos
Capacitación en salud ocular básica y sus derechosCapacitación en salud ocular básica y sus derechos
Capacitación en salud ocular básica y sus derechos
 
Tecnica de mininucleo
Tecnica de mininucleoTecnica de mininucleo
Tecnica de mininucleo
 
Dossier de Oftalmologia
Dossier de OftalmologiaDossier de Oftalmologia
Dossier de Oftalmologia
 
Romulo
RomuloRomulo
Romulo
 
Cirugía de las cataratas
Cirugía de las cataratasCirugía de las cataratas
Cirugía de las cataratas
 
Catarata
CatarataCatarata
Catarata
 
anatomia-ocular
anatomia-ocularanatomia-ocular
anatomia-ocular
 
Atlas oftalmología
Atlas oftalmologíaAtlas oftalmología
Atlas oftalmología
 
Programa de alta resolución en cirugía de catarata ambulante (ARCCA)
Programa de alta resolución en cirugía de catarata ambulante (ARCCA)Programa de alta resolución en cirugía de catarata ambulante (ARCCA)
Programa de alta resolución en cirugía de catarata ambulante (ARCCA)
 
Cirugia de Catarata
Cirugia de CatarataCirugia de Catarata
Cirugia de Catarata
 
Carnaval2009 01
Carnaval2009 01Carnaval2009 01
Carnaval2009 01
 
Nw2014 msics the_beginning05
Nw2014 msics the_beginning05Nw2014 msics the_beginning05
Nw2014 msics the_beginning05
 
Facofemto y mics
Facofemto y micsFacofemto y mics
Facofemto y mics
 
Parejas de futbolistas
Parejas de futbolistasParejas de futbolistas
Parejas de futbolistas
 
las chicas más lindas
las chicas más lindaslas chicas más lindas
las chicas más lindas
 
Manual small incision cataract surgery
Manual small incision cataract surgeryManual small incision cataract surgery
Manual small incision cataract surgery
 
Indicaciones y evaluación preoperatoria de la catarata
Indicaciones y evaluación preoperatoria de la catarataIndicaciones y evaluación preoperatoria de la catarata
Indicaciones y evaluación preoperatoria de la catarata
 

Ähnlich wie Sexy.js: A Sequential Ajax (Sajax) library for jQuery

international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
Simplify AJAX using jQuery
Simplify AJAX using jQuerySimplify AJAX using jQuery
Simplify AJAX using jQuery
Siva Arunachalam
 
React.js or why DOM finally makes sense
React.js or why DOM finally makes senseReact.js or why DOM finally makes sense
React.js or why DOM finally makes sense
Eldar Djafarov
 
Top Ten Web Defenses - DefCamp 2012
Top Ten Web Defenses  - DefCamp 2012Top Ten Web Defenses  - DefCamp 2012
Top Ten Web Defenses - DefCamp 2012
DefCamp
 

Ähnlich wie Sexy.js: A Sequential Ajax (Sajax) library for jQuery (20)

Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010
 
Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
Simplify AJAX using jQuery
Simplify AJAX using jQuerySimplify AJAX using jQuery
Simplify AJAX using jQuery
 
What's new in jQuery 1.5
What's new in jQuery 1.5What's new in jQuery 1.5
What's new in jQuery 1.5
 
jQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusionjQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusion
 
Test-driven Development with AEM
Test-driven Development with AEMTest-driven Development with AEM
Test-driven Development with AEM
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
jQuery
jQueryjQuery
jQuery
 
Reduxing like a pro
Reduxing like a proReduxing like a pro
Reduxing like a pro
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
 
React.js or why DOM finally makes sense
React.js or why DOM finally makes senseReact.js or why DOM finally makes sense
React.js or why DOM finally makes sense
 
jQuery's Secrets
jQuery's SecretsjQuery's Secrets
jQuery's Secrets
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Backbone js in drupal core
Backbone js in drupal coreBackbone js in drupal core
Backbone js in drupal core
 
Writing RESTful web services using Node.js
Writing RESTful web services using Node.jsWriting RESTful web services using Node.js
Writing RESTful web services using Node.js
 
Top Ten Web Defenses - DefCamp 2012
Top Ten Web Defenses  - DefCamp 2012Top Ten Web Defenses  - DefCamp 2012
Top Ten Web Defenses - DefCamp 2012
 

Kürzlich hochgeladen

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
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Sexy.js: A Sequential Ajax (Sajax) library for jQuery

  • 2. Sexy.js Slideshow http://www.slideshare.net/furf
  • 3. Sexy.js A lightweight JavaScript library which provides enhanced Sequential Ajax (Sajax) functionality and a sleek facade to jQuery’s native Ajax methods.
  • 4. Sexy.js Facilitates combination and manipulation of data from multiple sources Speeds loading of scripts, stylesheets, and data using parallel asynchronous HTTP requests
  • 5. Ugly.js $.getJSON('articles.json', function (articles) { $.getJSON('comments.json', function (comments) { $.getJSON('ratings.json', function (ratings) { $.each(comments, function (i, comment) { articles[comment.articleId].comments.push(comment); }); $.each(ratings, function (i, rating) { articles[rating.articleId].rating = rating; }); }); }); });
  • 6. Sexy.js Sexy .json('articles.json') .json('comments.json', function (comments, status, articles) { $.each(comments, function (i, comment) { articles[comment.articleId].comments.push(comment); }); return articles; }) .json('ratings.json', function (ratings, status, articles) { $.each(ratings, function (i, rating) { articles[rating.articleId].rating = rating; }); });
  • 7. Ugly.js <script src="/js/jquery.template.min.js" type="text/javascript"></script> <link rel="stylesheet" href="css/comments.css" type="text/css"/> <script type="text/javascript"> $.get('comments.tpl', function (tpl) { $.getJSON('comments.json', function (data) { $.template(tpl, data).appendTo('#comments'); }); }); </script>
  • 8. Sexy.js <script type="text/javascript"> Sexy .js('jquery.template.min.js') .css('comments.css') .text('comments.tpl') .json('comments.json', function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); }); </script>
  • 10. Sequential Ajax (Sajax) Simultaneous request/sequential response Ajax Each successive callback receives the return value of the previous callback as an additional argument
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 38. Sexy.js API Core Methods html (url, callback) json (url, callback) jsonp (url, callback) script/js (url, callback) style/css (url, callback) text (url, callback) xml (url, callback)
  • 39. Sexy.js API Core Methods html (url, callback) html (settings) json (url, callback) json (settings) jsonp (url, callback) jsonp (settings) script/js (url, callback) script/js (settings) style/css (url, callback) style/css (settings) text (url, callback) text (settings) xml (url, callback) xml (settings)
  • 40. Sexy.js API callback (data, status, previous) Each callback receives three arguments: data status previous - the return value of the previous callback (considering a fourth) next or this
  • 41. Sexy.js API Additional Methods setup (settings) Similar to jQuery.ajaxSetup, but limited to subsequent calls of a Sexy instance Can be unset with setup() bundle (url1, url2, ..., callback) Client-side JavaScript packaging Multiple file, single <script> injection Sequence is preserved
  • 43. Using Sexy.js Loading JavaScripts Sexy .js('jquery.template.min.js')
  • 44. Using Sexy.js Loading Stylesheets (local only) Sexy .js('jquery.template.min.js') .css('comments.css')
  • 45. Using Sexy.js Loading Stylesheets (local only) Sexy .js('jquery.template.min.js') .css('comments.css')
  • 46. Using Sexy.js Loading Data Sexy .js('jquery.template.min.js') .css('comments.css') .text('comments.tpl', function (data) { return data; })
  • 47. Using Sexy.js Loading Data Sexy .js('jquery.template.min.js') .css('comments.css') .text('comments.tpl', function (data) { return data; }) .json('comments.json', function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); });
  • 48. Using Sexy.js Custom Ajax Settings Sexy .js('jquery.template.min.js') .css('comments.css') .text('comments.tpl', function (data) { return data; }) .json({ url: 'comments.json', data: { article_id: 123, }, success: function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); } });
  • 49. Using Sexy.js Passing Data with Callbacks Sexy .js('jquery.template.min.js') .css('comments.css') .text('comments.tpl', function (data) { return data; }) .json('comments.json?article_id=123', function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); });
  • 50. Using Sexy.js Implicit Callbacks Sexy .js('jquery.template.min.js') .css('comments.css') .text('comments.tpl', function (data) { return data; }) .json('comments.json?article_id=123', function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); });
  • 51. Using Sexy.js Implicit Callbacks Sexy .js('jquery.template.min.js') .css('comments.css') .text('comments.tpl', function (data) { return data; }) .json('comments.json?article_id=123', function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); });
  • 52. Using Sexy.js Implicit Callbacks, Non-Data Types Sexy .css('comments.css') .text('comments.tpl') .js('jquery.template.min.js', function (data, status, previous) { return previous; }) .json('comments.json?article_id=123', function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); });
  • 53. Using Sexy.js Implicit Callbacks, Non-Data Types Sexy .css('comments.css') .text('comments.tpl') .js('jquery.template.min.js') .json('comments.json?article_id=123', function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); });
  • 54. Using Sexy.js Configuring Sexy.js Sexy .setup({ cache: true }) .js('jquery.template.min.js') .css('comments.css') .text('comments.tpl') .json('comments.json', function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); });
  • 55. Using Sexy.js Configuring Sexy.js Sexy({ cache: true }) .js('jquery.template.min.js') .css('comments.css') .text('comments.tpl') .json('comments.json', function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); });
  • 56. Using Sexy.js Configuring Sexy.js Sexy({ cache: true }) .js('jquery.template.min.js') .css('comments.css') .text('comments.tpl') .setup({ cache: false }) .json('comments.json', function (data, status, tpl) { $.template(tpl, data).appendTo('#comments'); });
  • 57. Using Sexy.js Bundling JavaScripts Sexy .bundle( '/js/bam.js', ‘/js/bam.datagrid.js', ‘/js/bam.stats.js', ‘/js/bam.stats.widget.js', ‘/js/bam.stats.widget.leagueSelector.js', ‘/js/bam.stats.app.js', ‘/js/bam.stats.app.sortablePlayerList.js' );
  • 58. Using Sexy.js Bundling JavaScripts Sexy .bundle( '/js/bam.js', ‘/js/bam.datagrid.js', ‘/js/bam.stats.js', ‘/js/bam.stats.widget.js', ‘/js/bam.stats.widget.leagueSelector.js', ‘/js/bam.stats.app.js', ‘/js/bam.stats.app.sortablePlayerList.js', function (src) { SortablePlayerList.init(); } );
  • 59. Known Issues Unable to detect error events for remote requests jsonp (remoteUrl) script (remoteUrl) style (remoteUrl)* *style (remoteUrl) will actually fire success event even if load was unsuccessful (ie. 404)
  • 60. Sexy.js Enhanced Ajax functionality Expressive, chainable API Lightweight (1.3KB compressed)
  • 61. Thanks! Slideshow: http://www.slideshare.net/furf URL: http://sexyjs.com Demo: http://sexyjs.com/demos/comments Download: http:github.com/furf/Sexy Twitter: @sexyjs E-mail: furf@furf.com
  • 63. Sexy is the new Sexy Sexy() == new Sexy() function Sexy (cfg) { // Allow instantiation without new keyword if (!(this instanceof Sexy)) { return new Sexy(cfg); } this.cfgs = []; this.setup(cfg); this.evt = $(this); }
  • 64. Take it off... take it all off! Sexy.method(url) == (new Sexy()).method(url) // Alias instance methods as static methods of constructor $.each(Sexy.prototype, function (name, method) { Sexy[name] = function () { return method.apply(new Sexy(), arguments); }; });

Hinweis der Redaktion