SlideShare une entreprise Scribd logo
1  sur  61
Single-Page-WebApp Architecture 程墨Morgan Cheng @morgancheng
Traditional Web Server Browser Web Page Page HTML Navigate Web Page Page HTML
Single Page WebApp Server Browser Page HTML Web Page Navigate XHR Response Navigate XHR Response
Not Just AJAX
It Should Work as Web
Bookmark-able Navigable Search-Engine-Friendly, if necessary
VS
Why to Single-Page?
Squeeze Bits for Better Experience
When to Single-Page?
Frequently Navigated Page Partial Difference Among Pages Performance Critical
How to Single-Page?
Now we totally depend on JavaScript
"The secret to building large apps is never build large apps. Break your applications into small pieces. Then, assemble those testable, bite-sized pieces into your big application"  -Justin Meyer,  author JavaScriptMVC
Singe Page App = Client Side Routing Client Side Rendering +
First, Client-Side Routing
Multiple Framework Choices https://github.com/addyosmani/todomvc
3.4.0 App F/W
Why YUI3.4 app framework doesn't allow to use hash style URL for all browsers? It was very important to make doing the right thing easy and doing the wrong thing hard. Ryan Grove
Server Just Render HTML Skeleton
Define Routes varcontroller = new Y.Controller( { 	routes:  	[ 	{ path: “/”, callback: onHomePage 	}, 	{ path: “/user/:guid”, callback: onUserPage 	} 	] }); onHomePage is invoked when route “/” is triggered
Dispatch on DOM Ready controller.dispatch(); Trigger route according to current page URL
Save on Navigation Y.delegate('click', onNaviLinkClick, 'body', '.navi-link', this); function onNaviLinkClick() {     … varnewPath = currTarget.getAttribute('href'); if (controller.getPath() != newPath) { controller.save(newPagePath);  	} } Trigger route according to newPagePath
Page Load & Page Navigation Routing Module Page B Page C Page A
Second, Client-Side Rendering
Page Load & Page Navigation Routing Module Page B Page C Page A Widget X Widget Y Widget Z
Widget or View-Model
Decouple Modules with Events
Page Load & Page Navigation Routing Module Page B Page C Page A Widget X Widget Y Widget Z Event System
Don’t Repeat Yourself
Logic-less Template: Mustache http://mustache.github.com/
<div id="post_{{pid}}” {{#post}} data-original-pid="{{pid}}"  {{/post}} > { pid: ‘123’,  post: { pid: ‘456’ 	} } <div id="post_123” data-original-pid=”456"  >
Ask Again: Why to Single-Page?
It should be Fast
近身== Download It Fast 发力 == Run It Fast
Download It Fast
Non-Blocking JavaScript
function loadJS(path) { varscript = document.createElement("script"); script.type = "text/javascript"; script.src = path;     document.getElementsByTagName("head")[0].appendChild(script); } Insert into <head>
Flush It!
 … </head> <?php ob_flush(); flush(); ?> <body> Flush for browser incremental rendering
WTF?
Position Inline JavaScript http://www.stevesouders.com/blog/2009/05/06/positioning-inline-scripts/
function loadJS(path) { varscript = document.createElement("script"); script.type = "text/javascript"; script.src = path; varfirst = document.getElementsByTagName(‘script’)[0]; first.parentNode.insertBefore(script, first); } Insert before first <script>
Position Inline JavaScript Before External Style Link
Caching: Better Than Downloading
Cache AJAX Inline Script Data Source Widget
Run It Fast
JavaScript Execution is Not Free
Client-side Rendering Depends on CPU & JS Engine
Mustache Performance Suffers From Nested Data
Performance is Not Good { pid: ‘123’,      entities:      { images:  [ 			{ image_medium: … , image_small: … , image_big: … , 			} 	] 	} }
Twice faster! { pid: ‘123’,      entities_images_0_image_medium: …,     entities_images_0_image_medium: …,     entities_images_0_image_medium: …, }
Chunked Computation
Web Worker
How to Render First Page?
Twitter Approach The first page response is just HTML skeleton Web is a client of its Open API The page is initialized with multiple AJAX response
Facebook Approach The first page response is HTML Skeleton with tailing inline JavaScript Init data is flushed in tailing JavaScript block It is called BigPipe The sequence of module rendering depends
Google+ Approach The first page response is complete HTML
Which is Better? Twitter Approach Facebook Approach Google+ Approach
Take-Away Leverage Framework Make decision according to app requirement Watch the Performance
Thank You!

Contenu connexe

Tendances

In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript AppsIn Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
Spike Brehm
 
General Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScriptGeneral Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScript
Spike Brehm
 

Tendances (20)

Overview about AngularJS Framework
Overview about AngularJS Framework Overview about AngularJS Framework
Overview about AngularJS Framework
 
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
 
Require js
Require jsRequire js
Require js
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
 
Story about module management with angular.js
Story about module management with angular.jsStory about module management with angular.js
Story about module management with angular.js
 
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript AppsIn Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
 
JSConf US 2014: Building Isomorphic Apps
JSConf US 2014: Building Isomorphic AppsJSConf US 2014: Building Isomorphic Apps
JSConf US 2014: Building Isomorphic Apps
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3
 
AngularJS - The Next Big Thing?
AngularJS - The Next Big Thing?AngularJS - The Next Big Thing?
AngularJS - The Next Big Thing?
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
 
Mvvm knockout vs angular
Mvvm knockout vs angularMvvm knockout vs angular
Mvvm knockout vs angular
 
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical UniversityASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
 
Muhammad azamuddin introduction-to-reactjs
Muhammad azamuddin   introduction-to-reactjsMuhammad azamuddin   introduction-to-reactjs
Muhammad azamuddin introduction-to-reactjs
 
The Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsThe Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.js
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
State of jQuery June 2013 - Portland
State of jQuery June 2013 - PortlandState of jQuery June 2013 - Portland
State of jQuery June 2013 - Portland
 
Performance monitoring measurement angualrjs single page apps with phantomas
Performance monitoring measurement angualrjs single page apps with phantomasPerformance monitoring measurement angualrjs single page apps with phantomas
Performance monitoring measurement angualrjs single page apps with phantomas
 
Single Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSingle Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with Angular
 
General Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScriptGeneral Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScript
 
Angular vs React: Building modern SharePoint interfaces with SPFx
Angular vs React: Building modern SharePoint interfaces with SPFxAngular vs React: Building modern SharePoint interfaces with SPFx
Angular vs React: Building modern SharePoint interfaces with SPFx
 

En vedette

Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
KMS Technology
 
AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application
Carlo Bonamico
 

En vedette (20)

Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
 
Single Page Applications
Single Page ApplicationsSingle Page Applications
Single Page Applications
 
Single-Page Application Design Principles 101
Single-Page Application Design Principles 101Single-Page Application Design Principles 101
Single-Page Application Design Principles 101
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Getting Single Page Application Security Right
Getting Single Page Application Security RightGetting Single Page Application Security Right
Getting Single Page Application Security Right
 
Single page applications
Single page applicationsSingle page applications
Single page applications
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentation
 
AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application
 
JS Single-Page Web App Essentials
JS Single-Page Web App EssentialsJS Single-Page Web App Essentials
JS Single-Page Web App Essentials
 
scope or not?
scope or not?scope or not?
scope or not?
 
Introduction to The Scalable JavaScript Application Framework
Introduction to The Scalable JavaScript Application FrameworkIntroduction to The Scalable JavaScript Application Framework
Introduction to The Scalable JavaScript Application Framework
 
Server and client rendering of single page apps
Server and client rendering of single page appsServer and client rendering of single page apps
Server and client rendering of single page apps
 
How to slice your monolithic webapp using MicroApps architecture
How to slice your monolithic webapp using MicroApps architectureHow to slice your monolithic webapp using MicroApps architecture
How to slice your monolithic webapp using MicroApps architecture
 
Eurosega equipo de profesionales altamente cualificados
Eurosega equipo de profesionales altamente cualificadosEurosega equipo de profesionales altamente cualificados
Eurosega equipo de profesionales altamente cualificados
 
We do it Roca style
We do it Roca styleWe do it Roca style
We do it Roca style
 
Content Architecture
Content ArchitectureContent Architecture
Content Architecture
 
Webapp-Architecture
Webapp-ArchitectureWebapp-Architecture
Webapp-Architecture
 
Today's Trending Technologies 2014
Today's Trending Technologies 2014Today's Trending Technologies 2014
Today's Trending Technologies 2014
 
5 single page application principles developers need to know
5 single page application principles developers need to know5 single page application principles developers need to know
5 single page application principles developers need to know
 
Testing your Single Page Application
Testing your Single Page ApplicationTesting your Single Page Application
Testing your Single Page Application
 

Similaire à Single Page WebApp Architecture

Advanced SEO for Web Developers
Advanced SEO for Web DevelopersAdvanced SEO for Web Developers
Advanced SEO for Web Developers
Nathan Buggia
 
Widget Summit 2008
Widget Summit 2008Widget Summit 2008
Widget Summit 2008
Volkan Unsal
 
Fast and Easy Website Tuneups
Fast and Easy Website TuneupsFast and Easy Website Tuneups
Fast and Easy Website Tuneups
Jeff Wisniewski
 
A World Beyond Ajax Accessing Googles Ap Is From Flash And Non Java Script En...
A World Beyond Ajax Accessing Googles Ap Is From Flash And Non Java Script En...A World Beyond Ajax Accessing Googles Ap Is From Flash And Non Java Script En...
A World Beyond Ajax Accessing Googles Ap Is From Flash And Non Java Script En...
GoogleTecTalks
 

Similaire à Single Page WebApp Architecture (20)

Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
Developing PHP Web Applications with the Raxan Framework
Developing PHP Web Applications with the Raxan FrameworkDeveloping PHP Web Applications with the Raxan Framework
Developing PHP Web Applications with the Raxan Framework
 
Oscon 20080724
Oscon 20080724Oscon 20080724
Oscon 20080724
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
Please dont touch-3.6-jsday
Please dont touch-3.6-jsdayPlease dont touch-3.6-jsday
Please dont touch-3.6-jsday
 
Web performance testing
Web performance testingWeb performance testing
Web performance testing
 
Real-World AJAX with ASP.NET
Real-World AJAX with ASP.NETReal-World AJAX with ASP.NET
Real-World AJAX with ASP.NET
 
GWT
GWTGWT
GWT
 
Lazy load Website Assets
Lazy load Website AssetsLazy load Website Assets
Lazy load Website Assets
 
Getting More Traffic From Search Advanced Seo For Developers Presentation
Getting More Traffic From Search  Advanced Seo For Developers PresentationGetting More Traffic From Search  Advanced Seo For Developers Presentation
Getting More Traffic From Search Advanced Seo For Developers Presentation
 
Advanced SEO for Web Developers
Advanced SEO for Web DevelopersAdvanced SEO for Web Developers
Advanced SEO for Web Developers
 
Bringing the JAMstack to the Enterprise
Bringing the JAMstack to the EnterpriseBringing the JAMstack to the Enterprise
Bringing the JAMstack to the Enterprise
 
Widget Summit 2008
Widget Summit 2008Widget Summit 2008
Widget Summit 2008
 
Fast and Easy Website Tuneups
Fast and Easy Website TuneupsFast and Easy Website Tuneups
Fast and Easy Website Tuneups
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09
 
How NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscapeHow NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscape
 
Course CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsCourse CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.js
 
Client Side Optimization
Client Side OptimizationClient Side Optimization
Client Side Optimization
 
AMP in WordPress, the WordPress Way
AMP in WordPress, the WordPress WayAMP in WordPress, the WordPress Way
AMP in WordPress, the WordPress Way
 
A World Beyond Ajax Accessing Googles Ap Is From Flash And Non Java Script En...
A World Beyond Ajax Accessing Googles Ap Is From Flash And Non Java Script En...A World Beyond Ajax Accessing Googles Ap Is From Flash And Non Java Script En...
A World Beyond Ajax Accessing Googles Ap Is From Flash And Non Java Script En...
 

Plus de Morgan Cheng (13)

React & Redux in Hulu
React & Redux in HuluReact & Redux in Hulu
React & Redux in Hulu
 
Flux and redux
Flux and reduxFlux and redux
Flux and redux
 
Critical thinking in Node.js
Critical thinking in Node.jsCritical thinking in Node.js
Critical thinking in Node.js
 
Engineering excellence 卓越工程
Engineering excellence 卓越工程Engineering excellence 卓越工程
Engineering excellence 卓越工程
 
High Performance Mobile Web
High Performance Mobile WebHigh Performance Mobile Web
High Performance Mobile Web
 
YUI vs jQuery: to Build Large Scale JavaScript App
YUI vs jQuery: to Build Large Scale JavaScript AppYUI vs jQuery: to Build Large Scale JavaScript App
YUI vs jQuery: to Build Large Scale JavaScript App
 
Secrets of Effective Presentation
Secrets of Effective PresentationSecrets of Effective Presentation
Secrets of Effective Presentation
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
 
Optimize URL for Performance
Optimize URL for PerformanceOptimize URL for Performance
Optimize URL for Performance
 
F2E's Creeds
F2E's CreedsF2E's Creeds
F2E's Creeds
 
Comet Server Push Over Web
Comet Server Push Over WebComet Server Push Over Web
Comet Server Push Over Web
 
Mobile Web on Touch Event and YUI
Mobile Web on Touch Event and YUIMobile Web on Touch Event and YUI
Mobile Web on Touch Event and YUI
 
Embracing YUI3 and Frontend Perf
Embracing YUI3 and Frontend PerfEmbracing YUI3 and Frontend Perf
Embracing YUI3 and Frontend Perf
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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?
 
[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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
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)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Single Page WebApp Architecture