SlideShare a Scribd company logo
1 of 26
BayJax




         YUI and NodeJS
           Running YUI on the Server


                          Adam Moore
                          YUI
                          http://developer.yahoo.com/yui/
                          adamoore@yahoo-inc.com
yaypie... “For the last few days @davglass has been blowing my
mind roughly hourly with what he's doing with node.js and YUI.
about 12 hours ago via Echofon ...”
YUI 3
• Modular
• Sandboxed
• Intrinsic component loading
• Core team + community
• Not just about manipulating the DOM
YUI 3
• Script Loading
• Remote i/o
• Events and Attributes
• Data Manipulation
• Language Utilities
• Templating
nodejs-yui3 @ github
• Replaces stock YUI 3 utilities
 • Console logger
 • Script transport
   • Loader and JSONP
 • XHR transport
Enabling YUI’s Loader
      • Testing loader
#!/usr/bin/env node
var YUI = require('../lib/node-yui3').YUI;

YUI({
    filter: 'debug'
}).use('event-custom', function(Y) {
    Y.on('cakeorpie', function() {
        Y.log('cheesecake');
    });

      Y.fire('cakeorpie');
});
Enabling YUI’s Loader
    • Testing loader
[~/examples (master)⚡] ➔ ./loader.js
[INFO]: (yui) Module requirements: event-custom
[INFO]: (yui) Modules missing: event-custom, 1
[INFO]: (yui) Fetching loader: yui_3_1_0_1_12711895820541, ./yui3/build/
loader/loader-debug.js
[INFO]: (get) URL: /lib/yui3/build/loader/loader-debug.js
[INFO]: (yui) Module requirements: yui-base,yui-log,dump,oop,yui-
later,event-custom
[INFO]: (yui) Modules missing: dump,oop,event-custom, 3
[INFO]: (yui) Using Loader
[INFO]: (loader) attempting to load dump, ./yui3/build/
[INFO]: (get) URL: /lib/yui3/build/dump/dump-debug.js
[INFO]: (loader) attempting to load oop, ./yui3/build/
[INFO]: (get) URL: /lib/yui3/build/oop/oop-debug.js
[INFO]: (loader) attempting to load event-custom, ./yui3/build/
[INFO]: (get) URL: /lib/yui3/build/event-custom/event-custom-debug.js
[INFO]: (loader) loader finishing: success, yui_3_1_0_1_12711895820541,
yui-base,yui-log,dump,oop,yui-later,event-custom
[INFO]: (event) yui_3_1_0_1_12711895820544: cakeorpie->sub:
yui_3_1_0_1_12711895820545
[INFO]: cheesecake
Accessing Remote Data
    • Using the YQL module from YUI Gallery
#!/usr/bin/env node

var sys = require('sys'),
    YUI = require('../lib/node-yui3').YUI;

YUI().use('json', 'gallery-yql', function(Y) {
    var q = 'select * from github.user.info where (id = "apm")',
         o = new Y.yql(q);
     o.on('query', function(r) {
          //Do something here.
          sys.puts(sys.inspect(r));
     });
});
Accessing Remote Data
      • Using the YQL module from YUI Gallery
[~/src/nodejs-yui3/examples (master)⚡] ➔ ./yql.js
[INFO]: (get) URL: http://query.yahooapis.com/v1/public/yql?q=select%20*
%20from%20github.user.info%20where%20(id%20%3D%20%22apm
%22)&format=json&callback=YUI.yql.yui_3_1_0_1_12711910026086&env=http%3A%2F
%2Fdatatables.org%2Falltables.env&

{   count: '1'
,   created: '2010-04-13T08:36:47Z'
,   lang: 'en-US'
,   results:
     { user:
        { 'gravatar-id': 'fd657f26f290d8869901f0eaf3441b97'
        , name: 'Adam Moore'
        , login: 'apm'
        // -snip-
        }
     }
}
Serving YUI with YUI
Serving YUI with YUI
    • Using YUI Loader on the server to create a
        combo service
<script src="http://yuiloader.davglass.com/"></script>
<script>
YUI({

 comboBase: 'http://yuiloader.davglass.com/?',

 combine: true
}).use('dd', function(Y) {
    var dd = new Y.DD.Drag({
        node: '#demo'
    });
});
</script>


http://yuiloader.davglass.com/demo/pr2.html
Serving YUI with YUI
    • Pre-fetch dependencies when loading YUI
<script src="http://yuiloader.davglass.com/?dd&io-base"></script>
<script>
    
YUI().use('dd', function(Y) {
    var dd = new Y.DD.Drag({
        node: '#demo'
    });
});
    
</script>



http://yuiloader.davglass.com/demo/shorty.html
Serving YUI with YUI
    • QuickYUI removes the need for the
        YUI().use() boilerplate code
<script src="http://yuiloader.davglass.com/quick?dd&widget&io"></script>
<script>

  // QuickYUI loads everything you want from a URL and sets up a
  // YUI instance assigned to Y

    var dd = new Y.DD.Drag({
        node: '#demo'
    });
    
</script>


http://yuiloader.davglass.com/demo/quick.html
Serving YUI with YUI
    • QuickYUI removes the need for the
        YUI().use() boilerplate code
<script src="http://yuiloader.davglass.com/quick?dd&widget&io"></script>
<script>

    // QuickYUI loads everything you want from a URL and sets up a
    // YUI instance assigned to Y

    var dd = new Y.DD.Drag({
        node: '#demo'
    });

    Y.use(‘slider’, function() {
        // load and instantiate a slider on demand
    });
    
</script>


http://yuiloader.davglass.com/demo/quick.html
Serving YUI with YUI
• YUI Loader is used on the server to
  expand the dependency tree, fetch, and
  combine YUI resources.
• Serves a JavaScript response.
• Iterative fetch
• Cache
• Also can combine custom resources.
What about the DOM?
• YUI isn’t all about the DOM
• But YUI has many DOM-centric modules.
• Being able to use these components on the
  server opens up some interesting
  opportunities.
Rendering HTML -
           nodejs-dom
•   Dav pulled together two open source
    projects to do it:
    •   jsdom - DOM level 1 support, written in
        JavaScript

    •   node-htmlparser - HTML parser written in
        JavaScript. Needed for innerHTML
Rendering HTML -
        nodejs-dom

•   DOM element creation and manipulation

•   Selector API

•   YUI’s Node API
Rendering HTML -
            nodejs-dom
• YUI HTML Service
#!/usr/bin/env node
var sys = require('sys'), http = require('http'), url = require('url');
var YUI = require("../lib/node-yui3").YUI;
YUI().use('nodejs-dom', 'node', function(Y) {
    var document = Y.Browser.document,
        navigator = Y.Browser.navigator,
        window    = Y.Browser.window;
    http.createServer(function (req, res) {
        var urlInfo = url.parse(req.url, true);
        YUI().use('nodejs-dom', 'node', function(Page) {
            document = Page.Browser.document;
            navigator = Page.Browser.navigator;
            window    = Page.Browser.window;
            document.title = 'Calendar Test';
            Page.one('body').addClass('yui-skin-sam');
            var ln = document.createElement('link');
            // ...
Rendering HTML



http://yuiloader.davglass.com/calendar/
Progressive Enhancement
•   YUI 2 calendar control is loaded via the YUI 2
    in 3 project

•   The calendar control is fully rendered on the
    server.

•   No script.

•   Page and nav clicks are round trips.

•   If script is enabled, we could enhance the links
    to pull only the data for each page and render
    on the client.
Multiple Response Types




http://yuiloader.davglass.com/template/
Multiple Response Types
•   First response will render the entire page.

•   A client without script can request the fully
    rendered page.

•   A script enabled client can request just the
    new content.

•   A script enabled client with the source that is
    running on the server can request just the
    JSON data structure that creates the content.

•   It’s the same code.
Other Uses


•   Fast utility layer testing with YUI Test.

•   Smoke tests for DOM-centric code.

    •   Could emulate some browser quirks.

•   Validation Code
Summary
•   YUI 3’s design made it easy to get running on
    NodeJS.

•   The core utilities have value on their own on
    the server side.

•   The addition of a server side DOM shows
    potential for creating complete web solutions
    from a single code base.
Resources
•   YUI: http://developer.yahoo.com/yui/

•   NodeJS: http://nodejs.org/

•   nodejs-yui: http://github.com/davglass/nodejs-yui3/

•   nodejs-yui3loader: http://github.com/davglass/nodejs-
    yui3loader

•   Test Loader: http://yuiloader.davglass.com/demo/

•   http://yuiloader.davglass.com/calendar/

More Related Content

What's hot

uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orgAgelos Pikoulas
 
Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usWebpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usStefan Adolf
 
Packer, where DevOps begins
Packer, where DevOps beginsPacker, where DevOps begins
Packer, where DevOps beginsJeff Hung
 
Juju Presentation 2011
Juju Presentation 2011Juju Presentation 2011
Juju Presentation 2011venturaphp
 
YUI - HackU 2010 IIT Mumbai
YUI - HackU 2010 IIT MumbaiYUI - HackU 2010 IIT Mumbai
YUI - HackU 2010 IIT Mumbaiknutties
 
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, MoscowJavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, MoscowRobert Nyman
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseAaron Silverman
 
MFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsMFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsPetr Dvorak
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Kris Wallsmith
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node jsfakedarren
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOSPetr Dvorak
 
2 docker engine_hands_on
2 docker engine_hands_on2 docker engine_hands_on
2 docker engine_hands_onFEG
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js PlatformDomenic Denicola
 
Building a js widget
Building a js widgetBuilding a js widget
Building a js widgetTudor Barbu
 
Single Page Applications in Drupal
Single Page Applications in DrupalSingle Page Applications in Drupal
Single Page Applications in DrupalChris Tankersley
 
Baking in the cloud with packer and puppet
Baking in the cloud with packer and puppetBaking in the cloud with packer and puppet
Baking in the cloud with packer and puppetAlan Parkinson
 

What's hot (20)

uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.org
 
Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usWebpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of us
 
Packer, where DevOps begins
Packer, where DevOps beginsPacker, where DevOps begins
Packer, where DevOps begins
 
Juju Presentation 2011
Juju Presentation 2011Juju Presentation 2011
Juju Presentation 2011
 
YUI - HackU 2010 IIT Mumbai
YUI - HackU 2010 IIT MumbaiYUI - HackU 2010 IIT Mumbai
YUI - HackU 2010 IIT Mumbai
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
 
Express js
Express jsExpress js
Express js
 
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, MoscowJavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
 
Packer
PackerPacker
Packer
 
MFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsMFF UK - Advanced iOS Topics
MFF UK - Advanced iOS Topics
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
2 docker engine_hands_on
2 docker engine_hands_on2 docker engine_hands_on
2 docker engine_hands_on
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js Platform
 
Express node js
Express node jsExpress node js
Express node js
 
Building a js widget
Building a js widgetBuilding a js widget
Building a js widget
 
Single Page Applications in Drupal
Single Page Applications in DrupalSingle Page Applications in Drupal
Single Page Applications in Drupal
 
Baking in the cloud with packer and puppet
Baking in the cloud with packer and puppetBaking in the cloud with packer and puppet
Baking in the cloud with packer and puppet
 

Viewers also liked (16)

El hockey
El hockeyEl hockey
El hockey
 
P1111223206
P1111223206P1111223206
P1111223206
 
An update on psychopharmacology part i 22 june 2007 fountain house
An update on psychopharmacology part i 22 june 2007 fountain houseAn update on psychopharmacology part i 22 june 2007 fountain house
An update on psychopharmacology part i 22 june 2007 fountain house
 
The year you where born
The year you where bornThe year you where born
The year you where born
 
Endocrinology
EndocrinologyEndocrinology
Endocrinology
 
常常喜樂
常常喜樂常常喜樂
常常喜樂
 
Transparency International Global Corruption Report 2009
Transparency International Global Corruption Report 2009 Transparency International Global Corruption Report 2009
Transparency International Global Corruption Report 2009
 
Nightingale Social & Cloud mockup
Nightingale Social & Cloud mockupNightingale Social & Cloud mockup
Nightingale Social & Cloud mockup
 
Template presentation
Template presentationTemplate presentation
Template presentation
 
Millat ibrahim - Abu Muhammad Maqdisi
Millat ibrahim - Abu Muhammad MaqdisiMillat ibrahim - Abu Muhammad Maqdisi
Millat ibrahim - Abu Muhammad Maqdisi
 
Patinatge
PatinatgePatinatge
Patinatge
 
E.C.G. Part 1
E.C.G. Part 1E.C.G. Part 1
E.C.G. Part 1
 
Selectivitat10
Selectivitat10Selectivitat10
Selectivitat10
 
Major_Proj_Ramya
Major_Proj_RamyaMajor_Proj_Ramya
Major_Proj_Ramya
 
Digital photography
Digital photographyDigital photography
Digital photography
 
P1121133746
P1121133746P1121133746
P1121133746
 

Similar to Running YUI 3 on Node.js - BayJax

JavaScript Everywhere! Creating a 100% JavaScript web stack
JavaScript Everywhere! Creating a 100% JavaScript web stackJavaScript Everywhere! Creating a 100% JavaScript web stack
JavaScript Everywhere! Creating a 100% JavaScript web stackTom Croucher
 
Node js实践
Node js实践Node js实践
Node js实践jay li
 
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012Eduardo Lundgren
 
Hack U - YUI - 2012 IIT Kharagpur
Hack U - YUI - 2012 IIT KharagpurHack U - YUI - 2012 IIT Kharagpur
Hack U - YUI - 2012 IIT KharagpurSumana Hariharan
 
Introduction to YUI PHP Loader
Introduction to YUI PHP LoaderIntroduction to YUI PHP Loader
Introduction to YUI PHP LoaderChad Auld
 
From YUI3 to K2
From YUI3 to K2From YUI3 to K2
From YUI3 to K2kaven yan
 
夜宴49期《YUI Conf 2010》
夜宴49期《YUI Conf 2010》夜宴49期《YUI Conf 2010》
夜宴49期《YUI Conf 2010》Koubei Banquet
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS偉格 高
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSGunnar Hillert
 
A New Vue for Web Development
A New Vue for Web DevelopmentA New Vue for Web Development
A New Vue for Web DevelopmentChad Campbell
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developerEdureka!
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperEdureka!
 
Best Practices in Widget Development - Examples and Counterexamples
Best Practices in Widget Development  - Examples and CounterexamplesBest Practices in Widget Development  - Examples and Counterexamples
Best Practices in Widget Development - Examples and CounterexamplesROLE Project
 

Similar to Running YUI 3 on Node.js - BayJax (20)

JavaScript Everywhere! Creating a 100% JavaScript web stack
JavaScript Everywhere! Creating a 100% JavaScript web stackJavaScript Everywhere! Creating a 100% JavaScript web stack
JavaScript Everywhere! Creating a 100% JavaScript web stack
 
Node js实践
Node js实践Node js实践
Node js实践
 
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
 
Hack U - YUI - 2012 IIT Kharagpur
Hack U - YUI - 2012 IIT KharagpurHack U - YUI - 2012 IIT Kharagpur
Hack U - YUI - 2012 IIT Kharagpur
 
Yui intro
Yui introYui intro
Yui intro
 
Introduction to YUI PHP Loader
Introduction to YUI PHP LoaderIntroduction to YUI PHP Loader
Introduction to YUI PHP Loader
 
From YUI3 to K2
From YUI3 to K2From YUI3 to K2
From YUI3 to K2
 
YUI for your Hacks
YUI for your Hacks YUI for your Hacks
YUI for your Hacks
 
夜宴49期《YUI Conf 2010》
夜宴49期《YUI Conf 2010》夜宴49期《YUI Conf 2010》
夜宴49期《YUI Conf 2010》
 
Banquet 49
Banquet 49Banquet 49
Banquet 49
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
 
Node azure
Node azureNode azure
Node azure
 
A New Vue for Web Development
A New Vue for Web DevelopmentA New Vue for Web Development
A New Vue for Web Development
 
Geode on Docker
Geode on DockerGeode on Docker
Geode on Docker
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
Best Practices in Widget Development - Examples and Counterexamples
Best Practices in Widget Development  - Examples and CounterexamplesBest Practices in Widget Development  - Examples and Counterexamples
Best Practices in Widget Development - Examples and Counterexamples
 
YUI3 - IIT Madras HackU
YUI3 - IIT Madras HackU YUI3 - IIT Madras HackU
YUI3 - IIT Madras HackU
 
YUI 3
YUI 3YUI 3
YUI 3
 

Running YUI 3 on Node.js - BayJax

  • 1. BayJax YUI and NodeJS Running YUI on the Server Adam Moore YUI http://developer.yahoo.com/yui/ adamoore@yahoo-inc.com
  • 2. yaypie... “For the last few days @davglass has been blowing my mind roughly hourly with what he's doing with node.js and YUI. about 12 hours ago via Echofon ...”
  • 3. YUI 3 • Modular • Sandboxed • Intrinsic component loading • Core team + community • Not just about manipulating the DOM
  • 4. YUI 3 • Script Loading • Remote i/o • Events and Attributes • Data Manipulation • Language Utilities • Templating
  • 5. nodejs-yui3 @ github • Replaces stock YUI 3 utilities • Console logger • Script transport • Loader and JSONP • XHR transport
  • 6. Enabling YUI’s Loader • Testing loader #!/usr/bin/env node var YUI = require('../lib/node-yui3').YUI; YUI({ filter: 'debug' }).use('event-custom', function(Y) { Y.on('cakeorpie', function() { Y.log('cheesecake'); }); Y.fire('cakeorpie'); });
  • 7. Enabling YUI’s Loader • Testing loader [~/examples (master)⚡] ➔ ./loader.js [INFO]: (yui) Module requirements: event-custom [INFO]: (yui) Modules missing: event-custom, 1 [INFO]: (yui) Fetching loader: yui_3_1_0_1_12711895820541, ./yui3/build/ loader/loader-debug.js [INFO]: (get) URL: /lib/yui3/build/loader/loader-debug.js [INFO]: (yui) Module requirements: yui-base,yui-log,dump,oop,yui- later,event-custom [INFO]: (yui) Modules missing: dump,oop,event-custom, 3 [INFO]: (yui) Using Loader [INFO]: (loader) attempting to load dump, ./yui3/build/ [INFO]: (get) URL: /lib/yui3/build/dump/dump-debug.js [INFO]: (loader) attempting to load oop, ./yui3/build/ [INFO]: (get) URL: /lib/yui3/build/oop/oop-debug.js [INFO]: (loader) attempting to load event-custom, ./yui3/build/ [INFO]: (get) URL: /lib/yui3/build/event-custom/event-custom-debug.js [INFO]: (loader) loader finishing: success, yui_3_1_0_1_12711895820541, yui-base,yui-log,dump,oop,yui-later,event-custom [INFO]: (event) yui_3_1_0_1_12711895820544: cakeorpie->sub: yui_3_1_0_1_12711895820545 [INFO]: cheesecake
  • 8. Accessing Remote Data • Using the YQL module from YUI Gallery #!/usr/bin/env node var sys = require('sys'), YUI = require('../lib/node-yui3').YUI; YUI().use('json', 'gallery-yql', function(Y) { var q = 'select * from github.user.info where (id = "apm")', o = new Y.yql(q); o.on('query', function(r) { //Do something here. sys.puts(sys.inspect(r)); }); });
  • 9. Accessing Remote Data • Using the YQL module from YUI Gallery [~/src/nodejs-yui3/examples (master)⚡] ➔ ./yql.js [INFO]: (get) URL: http://query.yahooapis.com/v1/public/yql?q=select%20* %20from%20github.user.info%20where%20(id%20%3D%20%22apm %22)&format=json&callback=YUI.yql.yui_3_1_0_1_12711910026086&env=http%3A%2F %2Fdatatables.org%2Falltables.env& { count: '1' , created: '2010-04-13T08:36:47Z' , lang: 'en-US' , results: { user: { 'gravatar-id': 'fd657f26f290d8869901f0eaf3441b97' , name: 'Adam Moore' , login: 'apm' // -snip- } } }
  • 11. Serving YUI with YUI • Using YUI Loader on the server to create a combo service <script src="http://yuiloader.davglass.com/"></script> <script> YUI({ comboBase: 'http://yuiloader.davglass.com/?', combine: true }).use('dd', function(Y) {     var dd = new Y.DD.Drag({         node: '#demo'     }); }); </script> http://yuiloader.davglass.com/demo/pr2.html
  • 12. Serving YUI with YUI • Pre-fetch dependencies when loading YUI <script src="http://yuiloader.davglass.com/?dd&io-base"></script> <script>      YUI().use('dd', function(Y) {     var dd = new Y.DD.Drag({         node: '#demo'     }); });      </script> http://yuiloader.davglass.com/demo/shorty.html
  • 13. Serving YUI with YUI • QuickYUI removes the need for the YUI().use() boilerplate code <script src="http://yuiloader.davglass.com/quick?dd&widget&io"></script> <script> // QuickYUI loads everything you want from a URL and sets up a // YUI instance assigned to Y     var dd = new Y.DD.Drag({         node: '#demo'     });      </script> http://yuiloader.davglass.com/demo/quick.html
  • 14. Serving YUI with YUI • QuickYUI removes the need for the YUI().use() boilerplate code <script src="http://yuiloader.davglass.com/quick?dd&widget&io"></script> <script> // QuickYUI loads everything you want from a URL and sets up a // YUI instance assigned to Y     var dd = new Y.DD.Drag({         node: '#demo'     }); Y.use(‘slider’, function() { // load and instantiate a slider on demand });      </script> http://yuiloader.davglass.com/demo/quick.html
  • 15. Serving YUI with YUI • YUI Loader is used on the server to expand the dependency tree, fetch, and combine YUI resources. • Serves a JavaScript response. • Iterative fetch • Cache • Also can combine custom resources.
  • 16. What about the DOM? • YUI isn’t all about the DOM • But YUI has many DOM-centric modules. • Being able to use these components on the server opens up some interesting opportunities.
  • 17. Rendering HTML - nodejs-dom • Dav pulled together two open source projects to do it: • jsdom - DOM level 1 support, written in JavaScript • node-htmlparser - HTML parser written in JavaScript. Needed for innerHTML
  • 18. Rendering HTML - nodejs-dom • DOM element creation and manipulation • Selector API • YUI’s Node API
  • 19. Rendering HTML - nodejs-dom • YUI HTML Service #!/usr/bin/env node var sys = require('sys'), http = require('http'), url = require('url'); var YUI = require("../lib/node-yui3").YUI; YUI().use('nodejs-dom', 'node', function(Y) { var document = Y.Browser.document, navigator = Y.Browser.navigator, window = Y.Browser.window; http.createServer(function (req, res) { var urlInfo = url.parse(req.url, true); YUI().use('nodejs-dom', 'node', function(Page) { document = Page.Browser.document; navigator = Page.Browser.navigator; window = Page.Browser.window; document.title = 'Calendar Test'; Page.one('body').addClass('yui-skin-sam'); var ln = document.createElement('link'); // ...
  • 21. Progressive Enhancement • YUI 2 calendar control is loaded via the YUI 2 in 3 project • The calendar control is fully rendered on the server. • No script. • Page and nav clicks are round trips. • If script is enabled, we could enhance the links to pull only the data for each page and render on the client.
  • 23. Multiple Response Types • First response will render the entire page. • A client without script can request the fully rendered page. • A script enabled client can request just the new content. • A script enabled client with the source that is running on the server can request just the JSON data structure that creates the content. • It’s the same code.
  • 24. Other Uses • Fast utility layer testing with YUI Test. • Smoke tests for DOM-centric code. • Could emulate some browser quirks. • Validation Code
  • 25. Summary • YUI 3’s design made it easy to get running on NodeJS. • The core utilities have value on their own on the server side. • The addition of a server side DOM shows potential for creating complete web solutions from a single code base.
  • 26. Resources • YUI: http://developer.yahoo.com/yui/ • NodeJS: http://nodejs.org/ • nodejs-yui: http://github.com/davglass/nodejs-yui3/ • nodejs-yui3loader: http://github.com/davglass/nodejs- yui3loader • Test Loader: http://yuiloader.davglass.com/demo/ • http://yuiloader.davglass.com/calendar/

Editor's Notes

  1. Service behind nginx
  2. Service behind nginx
  3. Progressive enhancement is no longer much more expensive -- it can be a natural outgrowth of the way your system works.
  4. Core + community -- core team building core platform, as with jQuery, but community extensions (more than 50 in the last release cycle) are first-class citizens
  5. Both NodeJS and YUI support chaining, so this can be done on one line if you like that sort of thing. The shebang isn&amp;#x2019;t a requirement, it just adds convenience when invoking the program ./hello.js vs node hello.js
  6. Loader manages the YUI dependencies. We can easily replace the transport Loader uses.
  7. Intrinsic gallery support works transparently Single combo URL for YUI and gallery
  8. YUI can load components on demand. You can keep your initial download to just what the application needs at the start.
  9. YUI can load components on demand. You can keep your initial download to just what the application needs at the start.
  10. Each request gets its own window and document Takes advantage of YUI&amp;#x2019;s innate ability to target a window or frame other than where the YUI script include resides
  11. show calendar example
  12. show template example
  13. It&apos;s worth emphasizing that these aren&apos;t theoretical benefits. Right now, most developers don&apos;t have time to build progressive enhancement into their projects and JS-dependent sites typically fail on devices that don&apos;t support JS (and sometimes fail when an error is introduced anywhere in the page, including by a third party ad). This approach enables things to work on more devices, with less development, and with less brittleness.
  14. I would love for you to say something like: &quot;At Yahoo and on the YUI team, we&apos;re passionate about web development and about JavaScript, and that&apos;s why we&apos;re interested in this and why we&apos;ve taken the time to ensure YUI 3 is there from the early days on Node. I&apos;ve worked hard to make sure that YUI 3 is both the most powerful and the most open project of its kind, and both the power -- from our intensely curated core -- and the openness -- from our friction-free gallery -- are available to you today in Node. (The YQL module we looked at earlier was a Gallery contribution, in fact.) The net result is that you can be writing YUI 3 modules that work on the client and the server and making those available to the world as part of the YUI 3 Gallery with very little effort. The biggest takeaway I want you to leave with is that you can participate in this process starting now, and the combination of YUI 3 and Node will give you unprecedented power and reach for your work.&quot;