This document discusses how server-side JavaScript is gaining popularity through frameworks like Node.js. It notes JavaScript can now be run on both the client-side through browsers and server-side through engines like V8, SpiderMonkey, and Rhino. Server-side JavaScript allows the same code to run on both client and server. The document also highlights how the YUI framework can be used with Node.js to build full-stack JavaScript applications that leverage YUI modules on both the front-end and back-end.
Unraveling Multimodality with Large Language Models.pdf
Let's run JavaScript Everywhere
1. Let’s run JavaScript
Everywhere
Why Server-side JavaScript is Taking Off
@sh1mmer Tom Hughes-Croucher
2. Why Server-Side JS?
• JavaScript Programmers
• Sophisticated client-side applications.
• Rich APIs provided by YUI and other
JavaScript libraries.
• The same code on the client or server.
• Progressive enhancement is no longer
much more expensive.
10. JavaScript is
• Proprietary to Netscape (now Mozilla)
• “Ahead” of ECMAScript
• Only really deployed in Mozilla projects
• Only usable on the server
11. ECMAScript is
• A standard
• Implemented in browsers
• ECMAScript-262 3rd ed. ~ JavaScript 1.5
• ECMAScript-262 5th ed. has no JavaScript
equivalent
12. JavaScript 1.6+
• E4X (EcmaScript For XML)
• Let scope blocks
• Generators
• Generator expressions
34. 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));
});
});
36. 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.
37. 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
• These are not nodeJS specific implementations
38. Rendering HTML -
nodejs-dom
• DOM element creation and manipulation
• Selector API
• YUI’s Node API
39. 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');
// ...
41. 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.
43. 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.
44. Other Uses
• Fast utility layer testing with YUI Test.
• Smoke tests for DOM-centric code.
• Could emulate some browser quirks.
• Validation Code
45. Node/YUI
• 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.
Progressive enhancement is no longer much more expensive -- it can be a natural outgrowth of the way your system works.
Service behind traffic server
Service behind nginx
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
Intrinsic gallery support works transparently
Single combo URL for YUI and gallery
show calendar example
show template example
It's worth emphasizing that these aren't theoretical benefits. Right now, most developers don't have time to build progressive enhancement into their projects and JS-dependent sites typically fail on devices that don'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.
I would love for you to say something like: "At Yahoo and on the YUI team, we're passionate about web development and about JavaScript, and that's why we're interested in this and why we've taken the time to ensure YUI 3 is there from the early days on Node. I'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."