SlideShare a Scribd company logo
1 of 46
Download to read offline
In Pursuit of the Holy Grail:
Building Isomorphic
JavaScript Apps
Spike Brehm
@spikebrehm
Spike Brehm
Software Engineer
@AirbnbNerds
Agenda
...TF is Isomorphic JavaScript?
Wat
...is it relevant to web developers?
Wy
...can I build isomorphic apps?
How
WTF is Isomorphic
JavaScript?
JavaScript code that can run
on both the client and server.
A brief note on
“isomorphic”.
“monomorphic”
“heteromorphic”
“homomorphic”
“multi-platform”
You’re using it wrong!
Isomorphic
JavaScript can be
or
shimmed per
environment .
environment-
agnostic
Does not depend on browser-
specific properties (window) or
server-specific properties
(process.env, req.cookies).
Environment-agnostic
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>
Provides shims for accessing
environment-specific properties so
module can expose a single API.
window.location.pathname	
vs.
req.path
Shimmed per environment
Example: Superagent
superagent!
.post('/api/posts.json')!
.send({ title: 'Moar JavaScript', body: '...' })!
.end(function(response) {!
if (response.status === 200) {!
console.log("Success!");!
} else {!
console.error("Error", response.body.error);!
}!
});
Isomorphic use
cases.
• Templating
• Routing
• I18n
• Date & currency formatting
• Model validation
• API interaction
• ...?
Isomorphic use cases.
Most of your
favorite libraries
can be used
isomorphically.
• Underscore.js
• Backbone.js
• Handlebars.js
• jQuery
• Moment
• React.js
• Polyglot.js (I18n)
Wy go to the
trouble?
Initial pageload speed.
Performance
Crawlable single-page apps.
SEO
Reduce code duplication.
Maintainability
Run code where you want.
Flexibility
Ye olde days:
fat-server, thin-
client.
Client
JavaScript
Server
Ruby
Python
Java
PHP
Persistence
View layer
Application logic
Routing
DOM manipulation Animations
Circa 2011:
thin-server, fat-
client.
Routing
View layer
Server
Ruby
Python
Java
PHP
Persistence
Client
JavaScript
Application logic
DOM manipulation Animations
Teh footure:
shared, fat-server,
fat-client.
Server
Ruby
Python
Java
PHP
Persistence
Client
JavaScript
Routing
View layer
Application logic
Shared
JavaScript
DOM manipulation Animations
Isomorphic
JavaScript is a
spectrum.
Entire view
layer and app
logic shared
Small bits of
view layer or
logic shared
Many
abstractions
Few
abstractions
ComplexSimple
View layer
shared
Entire app
runtime synced
between client
& server
How to Isomorphic.
The magic happens in the
build process.
Browserify & Grunt
Browserify
Use require() in the browser, the
same way you would on the server.
Package up CommonJS modules for
the browser.
Browserify
demo
!
github.com/
spikebrehm/isomorphic-examples
Task runner for automating build and
development workflow.
Grunt
Grunt
demo
!
github.com/
spikebrehm/isomorphic-examples
Wat about
shimmed per
environment?
How does Superagent do it?
Use package.json’s “browser” field
"browser": {
"./lib/node/index.js": “./lib/client.js",
"emitter": "emitter-component",
"reduce": "reduce-component"
},
“browser”: STRING || OBJECT,
“browser": "./lib/client.js",
Isomorphic
frameworks.
Mojito
Yahoo!; Full-stack; Never caught on.
Meteor
Realtime; Full-stack; Awesome.
No server-side rendering (yet).
Rendr
Airbnb; Library; Backbone & Handlebars.
Came from m.airbnb.com.
Towards an
isomorphic future.
JavaScript is the lingua
franca of the Web.
The Web is the platform;
JavaScript provides the runtime.
More reusable solutions;
more small modules.
It will be rare to see a web app
using no server-side JavaScript.
The revolution will come
in the build systems.
Static analysis, conditional builds,
source transforms.
Questions?
@AirbnbNerds

@spikebrehm
Thanks!

More Related Content

What's hot

Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
Morgan Cheng
 

What's hot (20)

Isomorphic web application
Isomorphic web applicationIsomorphic web application
Isomorphic web application
 
Refactoring to a Single Page Application
Refactoring to a Single Page ApplicationRefactoring to a Single Page Application
Refactoring to a Single Page Application
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
 
JavaScript Engine and WebAssembly
JavaScript Engine and WebAssemblyJavaScript Engine and WebAssembly
JavaScript Engine and WebAssembly
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
 
WebAssembly vs JavaScript: What is faster?
WebAssembly vs JavaScript: What is faster?WebAssembly vs JavaScript: What is faster?
WebAssembly vs JavaScript: What is faster?
 
Single page application and Framework
Single page application and FrameworkSingle page application and Framework
Single page application and Framework
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sails
 
Dev evening - MonoTouch, MonoDroid, Mvvm MvvmCross and databinding
Dev evening - MonoTouch, MonoDroid, Mvvm MvvmCross and databindingDev evening - MonoTouch, MonoDroid, Mvvm MvvmCross and databinding
Dev evening - MonoTouch, MonoDroid, Mvvm MvvmCross and databinding
 
SxSW 2015
SxSW 2015SxSW 2015
SxSW 2015
 
WordPress as a Platform - talk to Bristol Open Source Meetup, 2014-12-08
WordPress as a Platform - talk to Bristol Open Source Meetup, 2014-12-08WordPress as a Platform - talk to Bristol Open Source Meetup, 2014-12-08
WordPress as a Platform - talk to Bristol Open Source Meetup, 2014-12-08
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applications
 
MEAN stack
MEAN stackMEAN stack
MEAN stack
 
Handle the error
Handle the errorHandle the error
Handle the error
 
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?AngularJS vs React JS vs Node JS: Which is Best For Web Development ?
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?
 
Node.js with Express
Node.js with ExpressNode.js with Express
Node.js with Express
 
WebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction PresentationWebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction Presentation
 
WebAssembly Overview
WebAssembly OverviewWebAssembly Overview
WebAssembly Overview
 
Blazor
BlazorBlazor
Blazor
 

Similar to In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps

Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?
jbandi
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
Flu3nt highlights
Flu3nt highlightsFlu3nt highlights
Flu3nt highlights
dswork
 

Similar to In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps (20)

Isomorphic apps
Isomorphic appsIsomorphic apps
Isomorphic apps
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
 
Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?
 
(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
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Isomorphic javascript - Uppsala.js #8
Isomorphic javascript - Uppsala.js #8Isomorphic javascript - Uppsala.js #8
Isomorphic javascript - Uppsala.js #8
 
Service worker API
Service worker APIService worker API
Service worker API
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
 
Apache Flex and the imperfect Web
Apache Flex and the imperfect WebApache Flex and the imperfect Web
Apache Flex and the imperfect Web
 
soa
soasoa
soa
 
Web Development Today
Web Development TodayWeb Development Today
Web Development Today
 
Unit 4 Java script.pptx
Unit 4 Java script.pptxUnit 4 Java script.pptx
Unit 4 Java script.pptx
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
 
Quo vadis, JavaScript? Devday.pl keynote
Quo vadis, JavaScript? Devday.pl keynoteQuo vadis, JavaScript? Devday.pl keynote
Quo vadis, JavaScript? Devday.pl keynote
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
Flu3nt highlights
Flu3nt highlightsFlu3nt highlights
Flu3nt highlights
 
Webdevelopment
WebdevelopmentWebdevelopment
Webdevelopment
 
JavaScript New Tutorial Class XI and XII.pptx
JavaScript New Tutorial Class XI and XII.pptxJavaScript New Tutorial Class XI and XII.pptx
JavaScript New Tutorial Class XI and XII.pptx
 

More from Spike Brehm

Integrating Browserify with Sprockets
Integrating Browserify with SprocketsIntegrating Browserify with Sprockets
Integrating Browserify with Sprockets
Spike Brehm
 
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
Spike Brehm
 
Extending Apostrophe to build a variable-based CMS for rendering PDF brochures
Extending Apostrophe to build a variable-based CMS for rendering PDF brochuresExtending Apostrophe to build a variable-based CMS for rendering PDF brochures
Extending Apostrophe to build a variable-based CMS for rendering PDF brochures
Spike Brehm
 

More from Spike Brehm (6)

Managing Through Chaos (w/ presenter notes)
Managing Through Chaos (w/ presenter notes)Managing Through Chaos (w/ presenter notes)
Managing Through Chaos (w/ presenter notes)
 
Managing Through Chaos
Managing Through ChaosManaging Through Chaos
Managing Through Chaos
 
The Evolution of Airbnb's Frontend
The Evolution of Airbnb's FrontendThe Evolution of Airbnb's Frontend
The Evolution of Airbnb's Frontend
 
Integrating Browserify with Sprockets
Integrating Browserify with SprocketsIntegrating Browserify with Sprockets
Integrating Browserify with Sprockets
 
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
 
Extending Apostrophe to build a variable-based CMS for rendering PDF brochures
Extending Apostrophe to build a variable-based CMS for rendering PDF brochuresExtending Apostrophe to build a variable-based CMS for rendering PDF brochures
Extending Apostrophe to build a variable-based CMS for rendering PDF brochures
 

Recently uploaded

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
[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
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
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
 
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
 
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
 
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
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps