SlideShare a Scribd company logo
unlucio
Senior Software Engineer - Namshi
Dive Master - PADI
Remote Nerd - WEBdeBS
Back to the future:
Isomorphic javascript
applications
An isomorphic javascript application:
What is an “isomorphic application”
Why did we need one
How did we build it @ Namshi:
Requirements
Choices
What did we actually do
Isomorphism
Isomorphism is a very general concept that appears in several areas
of mathematics. The word derives from the Greek iso, meaning
"equal," and morphosis, meaning "to form" or "to shape.”
wolfram.com
http://mathworld.wolfram.com/Isomorphism.html
Isomorphic application
It’s a dynamic website capable of generating its html on
both server and client side, virtually using the same
exact code in both environments
and a website
is a bunch of nicely presented html
with an interactive layer on top
to be isomorphic
we need to stop at the html
take a note for future self!
Why do we need one?
Why do we need one?
Robots: search engines don’t cope with SPAs
Why do we need one?
Robots: search engines don’t cope with SPAs
Loading speed
Why do we need one?
Robots: search engines don’t cope with SPAs
Loading speed
Javascript doesn’t “fail safe”
@ Namshi…
We had to turn
this…
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion Dubai
in to
this
See the difference?
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion Dubai
SPA Page Isomorphic Page
SPA Page Isomorphic Page
~190Kb js Target 100Kb js
SPA Page Isomorphic Page
~190Kb js Target 100Kb js
~ 40p page speed at least 90p page speed
SPA Page Isomorphic Page
~190Kb js Target 100Kb js
~ 40p page speed at least 90p page speed
Angular.js ?????????
?????????
?????????
yup, we had to make a choice
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion Dubai
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion Dubai
We’re already using it on our SPAs
We’re already using it on our SPAs
Well known dependency injection
We’re already using it on our SPAs
Well known dependency injection
Data bindings
We’re already using it on our SPAs
Well known dependency injection
Data bindings
Jade (and we like it)
It’s ok but…
Making it isomorphic needs
quite a bit of tooling around
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion Dubai
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion Dubai
New and fashionable…
New and fashionable…
…we’re eager to try it :)
New and fashionable…
…we’re eager to try it :)
The virtual DOM looks amazing
New and fashionable…
…we’re eager to try it :)
The virtual DOM looks amazing
Flux (once you get it) seems quite a good idea
New and fashionable…
…we’re eager to try it :)
The virtual DOM looks amazing
Flux (once you get it) seems quite a good idea
JSX…
New and fashionable…
…we’re eager to try it :)
The virtual DOM looks amazing
Flux (once you get it) seems quite a good idea
JSX…
… but components are a nice idea too!
New and fashionable…
…we’re eager to try it :)
The virtual DOM looks amazing
Flux (once you get it) seems quite a good idea
JSX…
… but components are a nice idea too!
and The Internet says it can be isomorphic too!
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion Dubai
Let’s try it! :D
Examples and suggested techniques seems been
quite complex, with lots of structure and quite
opinionated
expectations slightly not met :’(
Yup, we’re back to square one…
Yup, we’re back to square one…
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion Dubai
ok… let’s try getting what we like…
ok… let’s try getting what we like…
data bindings
jade
flux
components
flux
capacitor
So, how does it work?
So, how does it work?
Step 1
Understand the view
Data Content
Template
Interaction
So, how does it work?
Step 2
Strip the interaction layer
Data Content
Template
Interaction
Remember our note: stop at the html.
So, how does it work?
What do we get form the api:
Data Content
{
data: [],
meta: {},
search: {}
}
{
data: “”,
meta: {},
search: {}
}
So, how does it work?
What do we get form the api:
{
data: “”,
meta: {},
search: {}
}
This guy is html!
So, how does it work?
Choose a template engine
Template
Jade:
our current angular ones
Nunjucks:
renders on client and server
let’s bring back
what we liked about React
Flux
Flux
Our data source: API
Flux
Our data source: API
State: the URL
Flux
Our data source: API
State: the URL
Add a little dispatcher to notify for data update
Show me the code!
Show me the code!
Server entry point
var app = require('express')();
var tpl = require(‘../shared/tpl');
var url = require('url');
app.get('*', function(req, res) {
var path = url.parse(req.url).pathname;
api.getData(path).then(function(data) {
var html = tpl.render('main.html', data);
res.end(html);
});
});
Show me the code!
And it’s client counterpart
var page = require('page');
page('*', function (ctx) {
var path = url.parse(ctx.path).pathname;
dispatcher.broadcast('URL_CHANGE', {url: path});
api.getData(path).then(function (data) {
dispatcher.broadcast('DATA_UPDATE', data);
});
});
page.start();
Components
Components
Activate on state update
Components
Activate on state update
Receive data
Components
Activate on state update
Receive data
Transform them if needed
Components
Activate on state update
Receive data
Transform them if needed
Delegate to templates for final html generation
Show me the code!
Show me the code!
Title Component
var tpl = require('../tpl');
var vpo = require('vpo');
module.exports = function(data) {
return tpl.render('title.html', {
text: vpo.get(data, 'meta.seo.pageTitle')
|| vpo.get(data, 'title')
|| 'Namshi.com'
});
};
Show me the code!
Title Template
<title data-iso-component="title">{{ text }}</title>
Hey but what about
my interaction?
Hey but what about my interaction?
well, according to legend: turns out that back in the 90s
humans were able to use websites simply clicking on links and
without fancy UI wow-effects
Hey but what about my interaction?
Interaction We call them: widgets
they react to UI changes
they attach to iso-components
interact with data-nm-*
and use VUE.js
Show me the code!
Show me the code!
var dispatcher = require(‘../../shared/dispatcher');
var menu = require('./menu');
var cart = require('../services/cart');
module.exports = function($dom) {
$dom.on('click', '#site_menu .search_trigger', function(e) {
dispatcher.broadcast(‘TOGGLE_SEARCH’);
e.preventDefault();
});
this.bind($dom, {data: { menu: menu, cart: cart }});
};
Show me the code!
<div id="site_header" data-iso-component="header"
data-nm-class="navigation_open: menu.shiftContent">
<ul id="site_menu">
<li><a href="" class="search_trigger">
<i>{{ 'search' | translate }}</i></a>
</li>
<li><a href="/cart/" class="cart_overview">
<span data-nm-text="cart.itemsCount">0</span></a>
</li>
</ul>
</div>
did we meet our target?
did we meet our target?
Isomorphism: yes :)
did we meet our target?
Isomorphism: yes :)
Size: 162kb (including templates)
did we meet our target?
Isomorphism: yes :)
Size: 162kb (including templates)
Page speed…
Page speed…
node.js
Browserify
Gulp
Nunjucks
Vanilla JS
express.js
VUE.js
Docker
Thank you for listening
Thank you for listening

More Related Content

What's hot (16)

PDF
Beyond MVC: from Model to Domain
Jeremy Cook
 
PDF
[Practical] Functional Programming in Rails
Gilbert B Garza
 
PDF
Best practices for crafting high quality PHP apps (php[world] 2019)
James Titcumb
 
PDF
Async queue-transaction
Fei (James) Liu
 
PDF
React.js & Om: A hands-on walkthrough of better ways to build web UIs
Adam Solove
 
PDF
Introduction to Asynchronous scala
Stratio
 
PDF
Best practices for crafting high quality PHP apps (PHP Yorkshire 2018)
James Titcumb
 
PDF
Deliver Business Value Faster with AWS Step Functions
Daniel Zivkovic
 
ODP
Scala Future & Promises
Knoldus Inc.
 
PDF
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
James Titcumb
 
PDF
Crafting Quality PHP Applications: an overview (PHPSW March 2018)
James Titcumb
 
PDF
Unfiltered Unveiled
Wilfred Springer
 
PDF
Conscious Decoupling - Lone Star PHP
CiaranMcNulty
 
PDF
Refactoring @ Mindvalley: Smells, Techniques and Patterns
Tristan Gomez
 
PDF
How to ship customer value faster with step functions
Yan Cui
 
PPT
Jquery 1
Manish Kumar Singh
 
Beyond MVC: from Model to Domain
Jeremy Cook
 
[Practical] Functional Programming in Rails
Gilbert B Garza
 
Best practices for crafting high quality PHP apps (php[world] 2019)
James Titcumb
 
Async queue-transaction
Fei (James) Liu
 
React.js & Om: A hands-on walkthrough of better ways to build web UIs
Adam Solove
 
Introduction to Asynchronous scala
Stratio
 
Best practices for crafting high quality PHP apps (PHP Yorkshire 2018)
James Titcumb
 
Deliver Business Value Faster with AWS Step Functions
Daniel Zivkovic
 
Scala Future & Promises
Knoldus Inc.
 
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
James Titcumb
 
Crafting Quality PHP Applications: an overview (PHPSW March 2018)
James Titcumb
 
Unfiltered Unveiled
Wilfred Springer
 
Conscious Decoupling - Lone Star PHP
CiaranMcNulty
 
Refactoring @ Mindvalley: Smells, Techniques and Patterns
Tristan Gomez
 
How to ship customer value faster with step functions
Yan Cui
 

Similar to Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion Dubai (20)

PDF
TPSE Thailand 2015 - Rethinking Web with React and Flux
Jirat Kijlerdpornpailoj
 
PPTX
Swift meetup22june2015
Claire Townend Gee
 
PDF
Rust: Systems Programming for Everyone
C4Media
 
PDF
Migrating Web SDK from JS to TS
Grigory Petrov
 
KEY
Architecting single-page front-end apps
Zohar Arad
 
PPTX
Will be an introduction to
Sayed Ahmed
 
PDF
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Tal Melamed
 
KEY
Notes (2012-06-08)
Chris Pitt
 
PDF
Yahoo is open to developers
Christian Heilmann
 
PDF
Ibm_interconnect_restapi_workshop
Shubhra Kar
 
PPT
Webservices
Nyros Technologies
 
PPT
Pascarello_Investigating JavaScript and Ajax Security
amiable_indian
 
PPTX
All a flutter about Flutter.io
Steven Cooper
 
PDF
Rapid API Development with LoopBack/StrongLoop
Raymond Camden
 
PDF
Future of Serverless
Yoav Avrahami
 
PDF
Donald Ferguson - Old Programmers Can Learn New Tricks
ServerlessConf
 
PPTX
PHP and Platform Independance in the Cloud
ZendCon
 
PDF
Introducing Placemaker
Christian Heilmann
 
KEY
Speed Welshpool - Transport Technology, Realtime, PODs and APIs
george_edwards
 
ODP
OSDC 2008 Apache Ofbiz Talk
Guy Gershoni
 
TPSE Thailand 2015 - Rethinking Web with React and Flux
Jirat Kijlerdpornpailoj
 
Swift meetup22june2015
Claire Townend Gee
 
Rust: Systems Programming for Everyone
C4Media
 
Migrating Web SDK from JS to TS
Grigory Petrov
 
Architecting single-page front-end apps
Zohar Arad
 
Will be an introduction to
Sayed Ahmed
 
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Tal Melamed
 
Notes (2012-06-08)
Chris Pitt
 
Yahoo is open to developers
Christian Heilmann
 
Ibm_interconnect_restapi_workshop
Shubhra Kar
 
Webservices
Nyros Technologies
 
Pascarello_Investigating JavaScript and Ajax Security
amiable_indian
 
All a flutter about Flutter.io
Steven Cooper
 
Rapid API Development with LoopBack/StrongLoop
Raymond Camden
 
Future of Serverless
Yoav Avrahami
 
Donald Ferguson - Old Programmers Can Learn New Tricks
ServerlessConf
 
PHP and Platform Independance in the Cloud
ZendCon
 
Introducing Placemaker
Christian Heilmann
 
Speed Welshpool - Transport Technology, Realtime, PODs and APIs
george_edwards
 
OSDC 2008 Apache Ofbiz Talk
Guy Gershoni
 
Ad

More from Codemotion Dubai (11)

PDF
Embrace chatOps, stop installing deployment software by Geshan Manandhar at C...
Codemotion Dubai
 
PDF
SMACK Stack - Fast Data Done Right by Stefan Siprell at Codemotion Dubai
Codemotion Dubai
 
PDF
Microservices for Mortals by Bert Ertman at Codemotion Dubai
Codemotion Dubai
 
PPTX
Patterns and practices for real-world event-driven microservices by Rachel Re...
Codemotion Dubai
 
PDF
Dockerize it: stop living in the past and embrace the future by Alex Nadalin
Codemotion Dubai
 
PDF
Modelling complex game economy with Neo4j by Yan Cui at Codemotion Dubai
Codemotion Dubai
 
PPTX
Chaos Testing with F# and Azure by Rachel Reese at Codemotion Dubai
Codemotion Dubai
 
PDF
Getting Developers hooked on your API by Nicolas Garnier at Codemotion Dubai
Codemotion Dubai
 
PDF
F# in social gaming by Yan Cui at Codemotion Dubai
Codemotion Dubai
 
PDF
Building event driven serverless apps by Danilo Poccia at Codemotion Dubai
Codemotion Dubai
 
PDF
Demystifying the 3D Web by Pietro Grandi @ Codemotion Dubai 2016
Codemotion Dubai
 
Embrace chatOps, stop installing deployment software by Geshan Manandhar at C...
Codemotion Dubai
 
SMACK Stack - Fast Data Done Right by Stefan Siprell at Codemotion Dubai
Codemotion Dubai
 
Microservices for Mortals by Bert Ertman at Codemotion Dubai
Codemotion Dubai
 
Patterns and practices for real-world event-driven microservices by Rachel Re...
Codemotion Dubai
 
Dockerize it: stop living in the past and embrace the future by Alex Nadalin
Codemotion Dubai
 
Modelling complex game economy with Neo4j by Yan Cui at Codemotion Dubai
Codemotion Dubai
 
Chaos Testing with F# and Azure by Rachel Reese at Codemotion Dubai
Codemotion Dubai
 
Getting Developers hooked on your API by Nicolas Garnier at Codemotion Dubai
Codemotion Dubai
 
F# in social gaming by Yan Cui at Codemotion Dubai
Codemotion Dubai
 
Building event driven serverless apps by Danilo Poccia at Codemotion Dubai
Codemotion Dubai
 
Demystifying the 3D Web by Pietro Grandi @ Codemotion Dubai 2016
Codemotion Dubai
 
Ad

Recently uploaded (20)

PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
PPTX
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
PPT
introductio to computers by arthur janry
RamananMuthukrishnan
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPTX
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
PPTX
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
PPTX
internet básico presentacion es una red global
70965857
 
DOCX
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PDF
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
PPT
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PDF
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
PPTX
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
PPT
Computer Securityyyyyyyy - Chapter 2.ppt
SolomonSB
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
西班牙武康大学毕业证书{UCAMOfferUCAM成绩单水印}原版制作
Taqyea
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
introductio to computers by arthur janry
RamananMuthukrishnan
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
internet básico presentacion es una red global
70965857
 
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
Computer Securityyyyyyyy - Chapter 2.ppt
SolomonSB
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
西班牙武康大学毕业证书{UCAMOfferUCAM成绩单水印}原版制作
Taqyea
 
Orchestrating things in Angular application
Peter Abraham
 

Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion Dubai