SlideShare a Scribd company logo
WISH LIST
server and client rendering of
single page apps
Thomas Heymann	

@thomasheymann	

github.com/cyberthom
WHAT WE’VE BUILT
WISH LIST
•  Shopping tool	

•  Track products	

	

•  Receive alerts	

•  Share lists
GOALS & OBJECTIVES
•  Improve UI	

•  Pull out wish list into separate stack of services	

•  Update front-end code using modern frameworks and best practices	

–  Perfect candidate for SPA due to mutability	

•  Minify duplication which led to inconsistencies
SHARED CONCERNS
Server	

 Client	

USER
INTERACTIONS	

LOGGING	

MONITORING	

ROUTING	

PRESENTATION
LOGIC	

APPLICATION DATA	

views / layout / templates	

models / collections /
business rules / API calls	

events / animations	

SITE FURNITURE	

ANALYTICS	

i18n	

translations / date and
currency formatting	

STYLING
•  Developers get DRY and MV*	

•  Users get best of both worlds: 	

–  fully rendered pages (instant content)	

–  responsiveness of SPA	

•  Business gets SEO	

	

•  Everybody’s happy 🌈😃🎉
ENVIRONMENT AGNOSTIC
•  EvenThoughtWorks agrees 👌	

TECH RADAR
http://www.thoughtworks.com/radar/#/techniques	

Client and server rendering with same code 	

	

Increasingly, HTML is rendered not only on the server but also on the client,
in the web browser. In many cases this split rendering will remain a necessity
but with the growing maturity of JavaScript templating libraries an interesting
approach has become viable: client and server rendering with same code. 	

HOLD ASSESS TRIAL ADOPT
ARCHITECTURE & TECH STACK
SYSTEMS OVERVIEW
WISHLIST	

 API	

SITE FURNITURE	

Aggregation Layer	

Presentation Layer	

API	

MAGAZINE	

API	

CATALOGUE	

Core Services	

& Storage
TECH STACK
SERVER	

 CLIENT	

node.js	

 IE8+	

Express	

 Backbone Router	

cheerio	

 jQuery	

Backbone	

Handlebars	

require.js	

App
•  Renders nested views	

•  Re-attaches views to DOM client-side	

APP COMPONENTS
VIEW ASSEMBLER	

ROUTER	

MODEL FACTORY	

SERIALIZER	

SYNCER	

•  Ignores duplicate requests and caches responses	

•  Injects headers	

•  Matches URLs and extracts params	

•  Executes controller logic	

•  Serializes app data to JSON server-side	

•  Deserializes app data client-side	

•  Creates models	

•  Enforces singletons for data bindings
PAGE REQUEST	

1.  Instantiate app	

2.  Dispatch route (run controller logic)	

3.  Render views	

4.  Serialize data (models/collections)	

5.  Decorate page with site furniture	

6.  Send response	

SERVER WORKFLOW
PAGE LOAD	

1.  Instantiate app	

2.  Deserialize data (models/collections)	

3.  Setup Backbone routes	

4.  Dispatch route (run controller logic)	

5.  Re-attach views	

PAGE NAVIGATION	

1.  Dispatch route (run controller logic)	

2.  Render views	

CLIENT WORKFLOW
HANDS ON
module.exports = function(options) {!
var options = options || {},!
App = options.app,!
route = options.route;!
!
return function(req, res, next) {!
var app = new App({!
language: req.params.language,!
authToken: req.cookies.sessionid!
});!
!
app!
.dispatch(route, req.params)!
.done(function(view) {!
var html = view.render().outerHTML(),!
bootstrap = JSON.stringify(app.serialize());!
res.send(html + '<script>' + bootstrap + '</script>');!
})!
.fail(next);!
};!
};!
SERVE APP MIDDLEWARE
WISH LIST CONTROLLER
route('/wishlist/:id', 'wishlist', function(id) {!
var app = this, api = app.wishlistApi;!
!
var allWishlists = api.getAllWishlists(),!
wishlist = api.getWishlist(id),!
allWishlistItems = api.getAllWishlistItems(id);!
!
var productList = new ProductListView({!
collection: allWishlistItems!
}),!
navigation = new NavigationView({!
model: wishlist,!
collection: allWishlists!
});!
mainView = new MainView({!
model: wishlist,!
views: {!
'append header': navigation,!
'inner [role=main]': productList!
}!
});!
!
return mainView.ready().then(function() {!
return mainView;!
});!
});!
MAIN TEMPLATE
<header>!
<h1>{{name}}</h1>!
!
{{#if isOwner}}!
<button>Manage</button>!
{{/if}}!
!
{{! Navigation }}!
</header>!
!
<div role="main">{{! Product List }}</div>!
CLIENT-SIDE BOOTSTRAPPING
<header>!
<h1>Wish List</h1> <button>Manage</button>!
<ul class="navigation">!
<li>...</li>!
</ul>!
</header>!
<div role="main">!
<ul class=“product-list">!
<li>...</li>!
</ul>!
</div>!
!
<script>!
var app = new App();!
!
app.deserialize({bootstrap});!
!
route('/wishlist/:id', 'wishlist', function(id) {!
app!
.dispatch(route, id)!
.done(function(view) {!
view.attach('.container');!
});!
});!
Backbone.history.start();!
</script>!
VOILA!
WHAT WE’VE LEARNED
•  Lots of code bridging differences between environments and libraries	

–  Introducing extra abstraction layer	

•  Routing is different	

–  Stateless server-side routing (new app instance for each request)	

–  Stateful client-side routing (holding on to app during page navigation)	

–  Express vs. Backbone routes (reversed order, paths, params)	

–  Redirects (302 vs. browser location)	

–  Serve mobile page based on user agent	

•  Fetching data is different (XMLHttpRequest vs. node request)	

COMPLEX PROBLEM
•  Caching is different	

–  Only ever fetch once per incoming request	

–  Tab could be left open for days	

–  Expire and re-fetch resources after x seconds client-side	

•  Error handling is different (HTTP error codes vs. popups)	

•  Sending email is borderline	

COMPLEX PROBLEM
•  Dependency management	

–  CommonJS runs client-side with browserify	

–  AMD runs server-side with require.js	

–  Both work but ideally language level support (ES6 Modules)	

•  Promises	

–  Q or jQuery Deferred	

–  Ideally one standard (ES6 Promises)	

ES5 IMMATURITY
•  Well known jQuery API for DOM manipulation and traversal	

•  Easy to pick up	

•  Can translate Backbone apps directly to the server	

•  No full blown JSDOM, but still slow	

CHEERIO
•  Airbnb Rendr	

–  One stop solution (Rendering, Serialization, Routing)	

–  Pure string concatenation using templates – Fast on the server	

–  Client-side rendering trashes and re-renders whole DOM (can cause
flicker and performance issues)	

•  Facebook React	

–  View rendering library (Bring your own MC)	

–  Virtual DOM approach: slow on the server but super fast client-side	

–  Fun fact: Inspired by DOOM III	

CHEERIO ALTERNATIVES
Rendering comment box with 1000 comments	

SERVER-SIDE PERFORMANCE
•  Very simple HTML – String concatenation will shine even more as markup
grows in complexity	

•  React has the edge over Cheerio – JSX uses precompiled objects so can be
heavily optimized byV8 (Cheerio parses strings into trees on runtime)	

RENDR	

REACT	

CHEERIO	

~ 110 ms	

~ 174 ms	

~ 204 ms
•  Load performance means time to content (not response time)	

–  Server-side DOM is slow but faster than serving empty pages	

•  Think of it as an enhancement to SPA	

–  Stateless service can be easily scaled up	

–  Respond with empty pages if load is too high and render client-side	

•  Client-side rendering performance equally important	

•  Decide per use case – In certain situations simple Express.js templating with
separate client-side JS might be better approach	

SO WHAT?
•  YES! 🌟😺✨	

•  Joy to develop once hard work is done	

•  Easy and fast to build rich UI and add new functionality	

•  But:	

•  Technique in its infants	

•  Better frameworks/solutions required	

WORTH IT?
THANKS!

More Related Content

What's hot

A 20 minute introduction to AngularJS for XPage developers
A 20 minute introduction to AngularJS for XPage developersA 20 minute introduction to AngularJS for XPage developers
A 20 minute introduction to AngularJS for XPage developers
Mark Leusink
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
Steve Souders
 
BP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPagesBP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPages
edm00se
 
Server rendering-talk
Server rendering-talkServer rendering-talk
Server rendering-talk
Daiwei Lu
 
Isomorphic React Applications: Performance And Scalability
Isomorphic React Applications: Performance And ScalabilityIsomorphic React Applications: Performance And Scalability
Isomorphic React Applications: Performance And Scalability
Denis Izmaylov
 
Develop a vanilla.js spa you and your customers will love
Develop a vanilla.js spa you and your customers will loveDevelop a vanilla.js spa you and your customers will love
Develop a vanilla.js spa you and your customers will love
Chris Love
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
Krishnaprasad k
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?
Balajihope
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
Chris Love
 
Testing your Single Page Application
Testing your Single Page ApplicationTesting your Single Page Application
Testing your Single Page Application
Wekoslav Stefanovski
 
The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014
Simona Clapan
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...
Mark Leusink
 
Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster
Boris Livshutz
 
Angular 2 vs React
Angular 2 vs ReactAngular 2 vs React
Angular 2 vs React
Iran Reyes Fleitas
 
Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4
Yuriy Shapovalov
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
Troy Miles
 
Refactoring to a Single Page Application
Refactoring to a Single Page ApplicationRefactoring to a Single Page Application
Refactoring to a Single Page Application
Codemotion
 
Angular.js in XPages
Angular.js in XPagesAngular.js in XPages
Angular.js in XPages
Mark Roden
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
Marcus Hellberg
 

What's hot (20)

A 20 minute introduction to AngularJS for XPage developers
A 20 minute introduction to AngularJS for XPage developersA 20 minute introduction to AngularJS for XPage developers
A 20 minute introduction to AngularJS for XPage developers
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 
BP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPagesBP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPages
 
Server rendering-talk
Server rendering-talkServer rendering-talk
Server rendering-talk
 
Isomorphic React Applications: Performance And Scalability
Isomorphic React Applications: Performance And ScalabilityIsomorphic React Applications: Performance And Scalability
Isomorphic React Applications: Performance And Scalability
 
Develop a vanilla.js spa you and your customers will love
Develop a vanilla.js spa you and your customers will loveDevelop a vanilla.js spa you and your customers will love
Develop a vanilla.js spa you and your customers will love
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
 
Testing your Single Page Application
Testing your Single Page ApplicationTesting your Single Page Application
Testing your Single Page Application
 
The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...
 
Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster
 
Angular 2 vs React
Angular 2 vs ReactAngular 2 vs React
Angular 2 vs React
 
Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
Refactoring to a Single Page Application
Refactoring to a Single Page ApplicationRefactoring to a Single Page Application
Refactoring to a Single Page Application
 
Angular.js in XPages
Angular.js in XPagesAngular.js in XPages
Angular.js in XPages
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
 

Similar to Server and client rendering of single page apps

The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...
Mark Roden
 
JavaScript MVC Frameworks: Backbone, Ember and Angular JS
JavaScript MVC Frameworks: Backbone, Ember and Angular JSJavaScript MVC Frameworks: Backbone, Ember and Angular JS
JavaScript MVC Frameworks: Backbone, Ember and Angular JS
Harbinger Systems - HRTech Builder of Choice
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
ASG
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
Sapna Upreti
 
Google app-engine-cloudcamplagos2011
Google app-engine-cloudcamplagos2011Google app-engine-cloudcamplagos2011
Google app-engine-cloudcamplagos2011
Opevel
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
cloudcampnigeria
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
Jeremy Likness
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best Practices
Andrew Ferrier
 
Ember App Kit & The Ember Resolver
Ember App Kit & The Ember ResolverEmber App Kit & The Ember Resolver
Ember App Kit & The Ember Resolver
tboyt
 
EmberJS BucharestJS
EmberJS BucharestJSEmberJS BucharestJS
EmberJS BucharestJS
Remus Rusanu
 
Build Modern Web Apps Using ASP.NET Web API and AngularJS
Build Modern Web Apps Using ASP.NET Web API and AngularJSBuild Modern Web Apps Using ASP.NET Web API and AngularJS
Build Modern Web Apps Using ASP.NET Web API and AngularJS
Taiseer Joudeh
 
How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...
Katia Aresti
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 
Good bye Massive View Controller!
Good bye Massive View Controller!Good bye Massive View Controller!
Good bye Massive View Controller!
Supercharge
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
Malam Team
 
(ATS6-DEV02) Web Application Strategies
(ATS6-DEV02) Web Application Strategies(ATS6-DEV02) Web Application Strategies
(ATS6-DEV02) Web Application Strategies
BIOVIA
 
Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
Lucas Jellema
 
Remix
RemixRemix
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav TulachJDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
PROIDEA
 
Building SharePoint Single Page Applications Using AngularJS
Building SharePoint Single Page Applications Using AngularJSBuilding SharePoint Single Page Applications Using AngularJS
Building SharePoint Single Page Applications Using AngularJS
SharePointInstitute
 

Similar to Server and client rendering of single page apps (20)

The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...
 
JavaScript MVC Frameworks: Backbone, Ember and Angular JS
JavaScript MVC Frameworks: Backbone, Ember and Angular JSJavaScript MVC Frameworks: Backbone, Ember and Angular JS
JavaScript MVC Frameworks: Backbone, Ember and Angular JS
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
Google app-engine-cloudcamplagos2011
Google app-engine-cloudcamplagos2011Google app-engine-cloudcamplagos2011
Google app-engine-cloudcamplagos2011
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best Practices
 
Ember App Kit & The Ember Resolver
Ember App Kit & The Ember ResolverEmber App Kit & The Ember Resolver
Ember App Kit & The Ember Resolver
 
EmberJS BucharestJS
EmberJS BucharestJSEmberJS BucharestJS
EmberJS BucharestJS
 
Build Modern Web Apps Using ASP.NET Web API and AngularJS
Build Modern Web Apps Using ASP.NET Web API and AngularJSBuild Modern Web Apps Using ASP.NET Web API and AngularJS
Build Modern Web Apps Using ASP.NET Web API and AngularJS
 
How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
 
Good bye Massive View Controller!
Good bye Massive View Controller!Good bye Massive View Controller!
Good bye Massive View Controller!
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
 
(ATS6-DEV02) Web Application Strategies
(ATS6-DEV02) Web Application Strategies(ATS6-DEV02) Web Application Strategies
(ATS6-DEV02) Web Application Strategies
 
Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
 
Remix
RemixRemix
Remix
 
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav TulachJDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
 
Building SharePoint Single Page Applications Using AngularJS
Building SharePoint Single Page Applications Using AngularJSBuilding SharePoint Single Page Applications Using AngularJS
Building SharePoint Single Page Applications Using AngularJS
 

Recently uploaded

zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 

Recently uploaded (20)

zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 

Server and client rendering of single page apps

  • 1. WISH LIST server and client rendering of single page apps Thomas Heymann @thomasheymann github.com/cyberthom
  • 3. WISH LIST •  Shopping tool •  Track products •  Receive alerts •  Share lists
  • 4. GOALS & OBJECTIVES •  Improve UI •  Pull out wish list into separate stack of services •  Update front-end code using modern frameworks and best practices –  Perfect candidate for SPA due to mutability •  Minify duplication which led to inconsistencies
  • 5. SHARED CONCERNS Server Client USER INTERACTIONS LOGGING MONITORING ROUTING PRESENTATION LOGIC APPLICATION DATA views / layout / templates models / collections / business rules / API calls events / animations SITE FURNITURE ANALYTICS i18n translations / date and currency formatting STYLING
  • 6. •  Developers get DRY and MV* •  Users get best of both worlds: –  fully rendered pages (instant content) –  responsiveness of SPA •  Business gets SEO •  Everybody’s happy 🌈😃🎉 ENVIRONMENT AGNOSTIC
  • 7. •  EvenThoughtWorks agrees 👌 TECH RADAR http://www.thoughtworks.com/radar/#/techniques Client and server rendering with same code Increasingly, HTML is rendered not only on the server but also on the client, in the web browser. In many cases this split rendering will remain a necessity but with the growing maturity of JavaScript templating libraries an interesting approach has become viable: client and server rendering with same code. HOLD ASSESS TRIAL ADOPT
  • 9. SYSTEMS OVERVIEW WISHLIST API SITE FURNITURE Aggregation Layer Presentation Layer API MAGAZINE API CATALOGUE Core Services & Storage
  • 10. TECH STACK SERVER CLIENT node.js IE8+ Express Backbone Router cheerio jQuery Backbone Handlebars require.js App
  • 11. •  Renders nested views •  Re-attaches views to DOM client-side APP COMPONENTS VIEW ASSEMBLER ROUTER MODEL FACTORY SERIALIZER SYNCER •  Ignores duplicate requests and caches responses •  Injects headers •  Matches URLs and extracts params •  Executes controller logic •  Serializes app data to JSON server-side •  Deserializes app data client-side •  Creates models •  Enforces singletons for data bindings
  • 12. PAGE REQUEST 1.  Instantiate app 2.  Dispatch route (run controller logic) 3.  Render views 4.  Serialize data (models/collections) 5.  Decorate page with site furniture 6.  Send response SERVER WORKFLOW
  • 13. PAGE LOAD 1.  Instantiate app 2.  Deserialize data (models/collections) 3.  Setup Backbone routes 4.  Dispatch route (run controller logic) 5.  Re-attach views PAGE NAVIGATION 1.  Dispatch route (run controller logic) 2.  Render views CLIENT WORKFLOW
  • 15. module.exports = function(options) {! var options = options || {},! App = options.app,! route = options.route;! ! return function(req, res, next) {! var app = new App({! language: req.params.language,! authToken: req.cookies.sessionid! });! ! app! .dispatch(route, req.params)! .done(function(view) {! var html = view.render().outerHTML(),! bootstrap = JSON.stringify(app.serialize());! res.send(html + '<script>' + bootstrap + '</script>');! })! .fail(next);! };! };! SERVE APP MIDDLEWARE
  • 16. WISH LIST CONTROLLER route('/wishlist/:id', 'wishlist', function(id) {! var app = this, api = app.wishlistApi;! ! var allWishlists = api.getAllWishlists(),! wishlist = api.getWishlist(id),! allWishlistItems = api.getAllWishlistItems(id);! ! var productList = new ProductListView({! collection: allWishlistItems! }),! navigation = new NavigationView({! model: wishlist,! collection: allWishlists! });! mainView = new MainView({! model: wishlist,! views: {! 'append header': navigation,! 'inner [role=main]': productList! }! });! ! return mainView.ready().then(function() {! return mainView;! });! });!
  • 17. MAIN TEMPLATE <header>! <h1>{{name}}</h1>! ! {{#if isOwner}}! <button>Manage</button>! {{/if}}! ! {{! Navigation }}! </header>! ! <div role="main">{{! Product List }}</div>!
  • 18. CLIENT-SIDE BOOTSTRAPPING <header>! <h1>Wish List</h1> <button>Manage</button>! <ul class="navigation">! <li>...</li>! </ul>! </header>! <div role="main">! <ul class=“product-list">! <li>...</li>! </ul>! </div>! ! <script>! var app = new App();! ! app.deserialize({bootstrap});! ! route('/wishlist/:id', 'wishlist', function(id) {! app! .dispatch(route, id)! .done(function(view) {! view.attach('.container');! });! });! Backbone.history.start();! </script>!
  • 21. •  Lots of code bridging differences between environments and libraries –  Introducing extra abstraction layer •  Routing is different –  Stateless server-side routing (new app instance for each request) –  Stateful client-side routing (holding on to app during page navigation) –  Express vs. Backbone routes (reversed order, paths, params) –  Redirects (302 vs. browser location) –  Serve mobile page based on user agent •  Fetching data is different (XMLHttpRequest vs. node request) COMPLEX PROBLEM
  • 22. •  Caching is different –  Only ever fetch once per incoming request –  Tab could be left open for days –  Expire and re-fetch resources after x seconds client-side •  Error handling is different (HTTP error codes vs. popups) •  Sending email is borderline COMPLEX PROBLEM
  • 23. •  Dependency management –  CommonJS runs client-side with browserify –  AMD runs server-side with require.js –  Both work but ideally language level support (ES6 Modules) •  Promises –  Q or jQuery Deferred –  Ideally one standard (ES6 Promises) ES5 IMMATURITY
  • 24. •  Well known jQuery API for DOM manipulation and traversal •  Easy to pick up •  Can translate Backbone apps directly to the server •  No full blown JSDOM, but still slow CHEERIO
  • 25. •  Airbnb Rendr –  One stop solution (Rendering, Serialization, Routing) –  Pure string concatenation using templates – Fast on the server –  Client-side rendering trashes and re-renders whole DOM (can cause flicker and performance issues) •  Facebook React –  View rendering library (Bring your own MC) –  Virtual DOM approach: slow on the server but super fast client-side –  Fun fact: Inspired by DOOM III CHEERIO ALTERNATIVES
  • 26. Rendering comment box with 1000 comments SERVER-SIDE PERFORMANCE •  Very simple HTML – String concatenation will shine even more as markup grows in complexity •  React has the edge over Cheerio – JSX uses precompiled objects so can be heavily optimized byV8 (Cheerio parses strings into trees on runtime) RENDR REACT CHEERIO ~ 110 ms ~ 174 ms ~ 204 ms
  • 27. •  Load performance means time to content (not response time) –  Server-side DOM is slow but faster than serving empty pages •  Think of it as an enhancement to SPA –  Stateless service can be easily scaled up –  Respond with empty pages if load is too high and render client-side •  Client-side rendering performance equally important •  Decide per use case – In certain situations simple Express.js templating with separate client-side JS might be better approach SO WHAT?
  • 28. •  YES! 🌟😺✨ •  Joy to develop once hard work is done •  Easy and fast to build rich UI and add new functionality •  But: •  Technique in its infants •  Better frameworks/solutions required WORTH IT?