SlideShare une entreprise Scribd logo
1  sur  55
Télécharger pour lire hors ligne
Master Class:
Isomorphic JavaScript

Spike Brehm
@spikebrehm
New iOS,
Android apps
launched
today

</marketing>
Agenda
Wat
...TF is Isomorphic JavaScript?

Wy
...is it relevant to web developers?

How
...can I build isomorphic apps?
WTF is Isomorphic
JavaScript?
JavaScript code that can run
on both the client and server.
A brief note on
“isomorphic”.
You’re using it wrong!
“monomorphic”
“heteromorphic”
“homomorphic”
“multi-platform”
Example, plz.
Example: Underscore.js
var posts = [{
id: 1,
title: 'JavaScript is cool'
}, {
id: 2,
title: 'The Web is the platform'
}];
 
_.pluck(posts, 'title');
// ['JavaScript is cool', 'The Web is the platform']
Ye olde days:
fat-serer, thinclient.
DOM
manipulation

Form
validation

Client
Animations

JavaScript

Serer
Routing
View layer
Application logic
Persistence

Ruby
Python
Java
PHP
Circa 2011:
thin-serer, fatclient.
DOM
manipulation

Form
validation

Client
Animations

JavaScript

Routing
View layer
Application logic

Serer
Persistence

Ruby
Python
Java
PHP
Teh footure:
shared, fat-serer,
fat-client.
DOM
manipulation

Form
validation

Client
Animations

JavaScript

Shared
Routing

JavaScript

View layer
Application logic

Serer
Persistence

Ruby
Python
Java
PHP
Isomorphic
JavaScript can be
environmentagnostic
or
shimmed per
environment .
Environment-agnostic
Does not depend on browserspecific properties (window) or
server-specific properties
(process.env, req.cookies).
Example: Handlebars.js
var template =
'<ul>' 
'{{#each posts}}' 
' <li>{{title}}</li>' 
'{{/each}}' 
'</ul>'
;
 
var templateFn = Handlebars.compile(template)
, html = templateFn({posts: posts});
// <ul>
//
<li>JavaScript is cool</li>
//
<li>The Web is the platform</li>
// </ul>
Shimmed per environment
Provides shims for accessing
environment-specific properties so
module can expose a single API.
window.location.pathname
vs.
req.path
Example: Superagent
superagent
.post('/api/posts.json')
.send({ title: 'Moar JavaScript', body: '...' })
.set('X-Api-KEY', '123456abcdef')
.end(function(response) {
if (response.status === 200) {
console.log("Success!");
} else {
console.error("Error", response.body.error);
}
});
Isomorphic use
cases.
Isomorphic use cases.
• Templating
• Routing
• I18n
• Date

& currency formatting
• Model validation
• API interaction
• ...?
Most of your
favorite libraries
can be used
isomorphically.
• Underscore.js
• Backbone.js
• Handlebars.js
• jQuery
• Moment
• React.js
• Polyglot.js

(I18n)
Isomorphic
JavaScript is a
spectrum.
Small bits of
view layer or
logic shared

Entire view
layer and app
logic shared
Few
abstractions

Many
abstractions
Simple

Complex
View layer
shared

Entire app
runtime synced
between client
& server
Wy go to the
trouble?
Performance
Initial pageload speed.

SEO
Crawlable single-page apps.

Maintainability
Reduce code duplication.
Building and
bundling.
Browserif
Package up CommonJS modules
for the browser.
Use ‘require()’ in the browser, the
same way you would on the server.
Browserif
// app/template_renderer.js
 
var handlebars = require('handlebars');
 
module.exports = function(templatePath, data) {
var templateFn = require('./views/' + templatePath)
, html = templateFn(data);
return html;
};

Bundles a module and all its dependencies.
Grunt
Task runner for automating build
and development workflow.
Grunt
• Compile

Handlebars templates
• Run Browserify to package up
your shared app files
• Recompile files and restart Node
server on every change
Any questions thus
far?
Hack time.
Sample Node.js app
Combines a few modules together
for MVP of isomorphic app.

Express.js blog platform
Basic web server with RESTful API.
Handlebars.js
Templating.

Superagent
HTTP requests to API.

Director
Routing HTTP and HTML5.
Tour of the app.
Setting up locally.
Clone the sample app
git clone git@github.com:spikebrehm/
isomorphic-tutorial.git

github.com/spikebrehm/isomorphic-tutorial
Ensure Node >= 0.8.x
$ node --version
v0.10.21

Have to install?
$ brew install node
or
http://nodejs.org
github.com/spikebrehm/isomorphic-tutorial
Install `grunt-cli`
$ npm install grunt-cli -g

github.com/spikebrehm/isomorphic-tutorial
Run `npm install`
$ cd isomorphic-tutorial
$ npm install

github.com/spikebrehm/isomorphic-tutorial
Run the serer!
$ grunt server

View `localhost:3030` in browser

github.com/spikebrehm/isomorphic-tutorial
Let’s add a feature.
Date formatting
Before:
After:

Moment
moment('2013-11-04T17:23:01.329Z').format('LLLL');
// "Monday, November 4 2013 9:23 AM"
Add Moment using NPM
$ npm install moment --save
Create `formatDate`
Handlebars helper
Posted at {{created_at}}
Posted at {{formatDate created_at}}

function formatDate(dateStr) {
return moment(dateStr).format('LLLL');
}
Questions?
Thanks!
@AirbnbNerds
@spikebrehm

Contenu connexe

Tendances

Tendances (20)

Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sails
 
JavaScript Engine and WebAssembly
JavaScript Engine and WebAssemblyJavaScript Engine and WebAssembly
JavaScript Engine and WebAssembly
 
Node.js with Express
Node.js with ExpressNode.js with Express
Node.js with Express
 
WebAssembly vs JavaScript: What is faster?
WebAssembly vs JavaScript: What is faster?WebAssembly vs JavaScript: What is faster?
WebAssembly vs JavaScript: What is faster?
 
Refactoring to a Single Page Application
Refactoring to a Single Page ApplicationRefactoring to a Single Page Application
Refactoring to a Single Page Application
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET Core
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 
Back to the future: Isomorphic javascript applications
Back to the future:  Isomorphic javascript applicationsBack to the future:  Isomorphic javascript applications
Back to the future: Isomorphic javascript applications
 
Mvvm knockout vs angular
Mvvm knockout vs angularMvvm knockout vs angular
Mvvm knockout vs angular
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?
 
The Evolution of Airbnb's Frontend
The Evolution of Airbnb's FrontendThe Evolution of Airbnb's Frontend
The Evolution of Airbnb's Frontend
 
Advanced Technology Days 15 - Visual Studio Productivity
Advanced Technology Days 15 - Visual Studio ProductivityAdvanced Technology Days 15 - Visual Studio Productivity
Advanced Technology Days 15 - Visual Studio Productivity
 
WebAssembly in Houdini CSS, is it possible?
WebAssembly in Houdini CSS, is it possible?WebAssembly in Houdini CSS, is it possible?
WebAssembly in Houdini CSS, is it possible?
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Node js projects
Node js projectsNode js projects
Node js projects
 
Fast Slim Correct: The History and Evolution of JavaScript.
Fast Slim Correct: The History and Evolution of JavaScript.Fast Slim Correct: The History and Evolution of JavaScript.
Fast Slim Correct: The History and Evolution of JavaScript.
 
Blazor
BlazorBlazor
Blazor
 

En vedette

En vedette (20)

Cut The Cruft - Everett Sizemore - MozTalk Denver - 2016
Cut The Cruft - Everett Sizemore - MozTalk Denver - 2016Cut The Cruft - Everett Sizemore - MozTalk Denver - 2016
Cut The Cruft - Everett Sizemore - MozTalk Denver - 2016
 
Perfect Starts: How to Get the Right Traffic with a Content Audit
Perfect Starts: How to Get the Right Traffic with a Content AuditPerfect Starts: How to Get the Right Traffic with a Content Audit
Perfect Starts: How to Get the Right Traffic with a Content Audit
 
Fight Back Against Back: How Search Engines & Social Networks' AI Impacts Mar...
Fight Back Against Back: How Search Engines & Social Networks' AI Impacts Mar...Fight Back Against Back: How Search Engines & Social Networks' AI Impacts Mar...
Fight Back Against Back: How Search Engines & Social Networks' AI Impacts Mar...
 
Frontend talk for backenders
Frontend talk for backendersFrontend talk for backenders
Frontend talk for backenders
 
Alloy Cybersecurity
Alloy CybersecurityAlloy Cybersecurity
Alloy Cybersecurity
 
Burman GSC Gurgaon
Burman GSC GurgaonBurman GSC Gurgaon
Burman GSC Gurgaon
 
Strategies to Drive Web Traffic in the Real Estate World
Strategies to Drive Web Traffic in the Real Estate WorldStrategies to Drive Web Traffic in the Real Estate World
Strategies to Drive Web Traffic in the Real Estate World
 
SEO: Crawl Budget Optimierung & Onsite SEO
SEO: Crawl Budget Optimierung & Onsite SEOSEO: Crawl Budget Optimierung & Onsite SEO
SEO: Crawl Budget Optimierung & Onsite SEO
 
Crawl Budget Optimization - SMX München 2016
Crawl Budget Optimization - SMX München 2016Crawl Budget Optimization - SMX München 2016
Crawl Budget Optimization - SMX München 2016
 
Incorporating Clicks, Attention and Satisfaction into a SERP Evaluation Model
Incorporating Clicks, Attention and Satisfaction into a SERP Evaluation ModelIncorporating Clicks, Attention and Satisfaction into a SERP Evaluation Model
Incorporating Clicks, Attention and Satisfaction into a SERP Evaluation Model
 
The Paradox of Great Content
The Paradox of Great ContentThe Paradox of Great Content
The Paradox of Great Content
 
Link Building's Tipping Point
Link Building's Tipping PointLink Building's Tipping Point
Link Building's Tipping Point
 
The Remarkable SEO Power of Republishing
The Remarkable SEO Power of RepublishingThe Remarkable SEO Power of Republishing
The Remarkable SEO Power of Republishing
 
Swarm.js: реактивная синхронизация данных — Виктор Грищенко — MoscowJS 13
Swarm.js: реактивная синхронизация данных — Виктор Грищенко — MoscowJS 13Swarm.js: реактивная синхронизация данных — Виктор Грищенко — MoscowJS 13
Swarm.js: реактивная синхронизация данных — Виктор Грищенко — MoscowJS 13
 
Built to Last
Built to LastBuilt to Last
Built to Last
 
Talk at FullStack 2016: Automating documentation on JavaScript projects
Talk at FullStack 2016: Automating documentation on JavaScript projectsTalk at FullStack 2016: Automating documentation on JavaScript projects
Talk at FullStack 2016: Automating documentation on JavaScript projects
 
WebPagetest Power Users - Velocity 2014
WebPagetest Power Users - Velocity 2014WebPagetest Power Users - Velocity 2014
WebPagetest Power Users - Velocity 2014
 
Enterprise JavaScript Error Handling (Ajax Experience 2008)
Enterprise JavaScript Error Handling (Ajax Experience 2008)Enterprise JavaScript Error Handling (Ajax Experience 2008)
Enterprise JavaScript Error Handling (Ajax Experience 2008)
 
Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012
 
Teaming Workshops
Teaming WorkshopsTeaming Workshops
Teaming Workshops
 

Similaire à Isomorphic JavaScript: #DevBeat Master Class

Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
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
Edureka!
 

Similaire à Isomorphic JavaScript: #DevBeat Master Class (20)

Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
 
Node js
Node jsNode js
Node js
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Reactjs Basics
Reactjs BasicsReactjs Basics
Reactjs Basics
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
Java script framework
Java script frameworkJava script framework
Java script framework
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Javascript Client & Server Architectures
Javascript Client & Server ArchitecturesJavascript Client & Server Architectures
Javascript Client & Server Architectures
 
React Js vs Node Js_ Which Framework to Choose for Your Next Web Application
React Js vs Node Js_ Which Framework to Choose for Your Next Web ApplicationReact Js vs Node Js_ Which Framework to Choose for Your Next Web Application
React Js vs Node Js_ Which Framework to Choose for Your Next Web Application
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
Introduction to meteor
Introduction to meteorIntroduction to meteor
Introduction to meteor
 
Web Development Today
Web Development TodayWeb Development Today
Web Development Today
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
 
(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe
 
Getting Started with J2EE, A Roadmap
Getting Started with J2EE, A RoadmapGetting Started with J2EE, A Roadmap
Getting Started with J2EE, A Roadmap
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
 
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
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 

Dernier

+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
+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...
 
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...
 
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
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Isomorphic JavaScript: #DevBeat Master Class