SlideShare a Scribd company logo
Universal JavaScript ?
SOHO
(Jerry-Hong)
Universal JavaScript ?
Universal JavaScript
• Isomorphic JavaScript
• Isomorphic JavaScript Single Page Application
Client Server SPA
• Universal JavaScript Isomorphic JavaScript
• Single Page Application
Single Page Application (SPA)
• (User Experience)
•
• AJAX, Client-Side Render, Client-Side Router
• Gmail, kkbox web player
Server-rendered Server-rendered + AJAX SPA
Load Performance
Dev Effort
User Experence
From: How instagram.com Works
SPA
SPA
1.
2.
Universal JavaScript
•
class MyTitle extends Component {
render() {
return (
<h1>Hello World</h1>
);
}
}
React
Vue.component('my-title', {
render(h) {
return (
<h1>Hello World</h1>
);
}
})
Vue 2 (JSX)
Vue.component('my-title', {
template: '<h1>Hello World</h1>'
})
Vue 2
@Component({
selector: 'my-title',
template: '<h1>Hello World</h1>'
})
class MyTitle { }
NG 2
•
•
• Flux
• Redux
• Vuex
• CSS class scope
• CSS module
• web component
• vue style scpoed
• View
• Server-Side Render
• Native app
•
•
• Flux
• Redux
• Vuex
• CSS Class Scope
• CSS module
• web component
• vue style scpoed
• View
• Server-Side Render
• Native app
•
•
• Flux
• Redux
• Vuex
• CSS class scope
• CSS module
• web component
• vue style scpoed
• View
• Server-Side Render
• Native app
.
.
.
2.
3. SEO
Universal JavaScript
4. First Time Loading
Universal JavaScript
- React / Redux
• SPA Server Template Engine
• SPA Function (F)
F(n)
F(n) => HTML
• SPA Server Client Server
• Function (F)
• request F HTML
• request Client SPA
SPA Universal JS?
Universal JavaScript
Universal JavaScript
Universal JavaScript
Universal JavaScript
Universal JavaScript
• (1~ 5)
•
•
Universal JS -
Step 1. Router
app
.use(compress())
.use(serve('./static')))
.use(router.routes())
.use(serverRender)
.use(errorBoot)
.listen(process.env.PORT || 8080,
() => {
console.log('listen 3000')
});
Step 1 - Router
• Server Router
API
app
.use(compress())
.use(serve('./static')))
.use(router.routes())
.use(serverRender)
.use(errorBoot)
.listen(process.env.PORT || 8080,
() => {
console.log('listen 3000')
});
Step 1 - Router
• Server Router
API
• Server Render
const store = createStore();
const childRoutes = createRoute(store);
match({
routes: childRoutes,
location: ctx.request.url
}, (error, redirectLocation, renderProps) => {
if (error) { // 500 }
else if (redirectLocation) { // 300 }
else if (renderProps) {
const component = (
<Provider store={ store }>
<RouterContext { ...renderProps }/>
</Provider>
);
const content = ReactDOMServer.renderToString(component);
ctx.response.type = 'text/html';
ctx.body = `<!DOCTYPE html> ... ${content}...</html>`
}
});
app
.use(compress())
.use(serve('./static')))
.use(router.routes())
.use(serverRender)
.use(errorBoot)
.listen(process.env.PORT || 8080,
() => {
console.log('listen 3000')
});
Step 1 - Router
• Server Router
API
• Server Render
•
Step 2. AJAX
• SPA ComponentDidMount AJAX
• Server Render ComponentWillMount Render
• Server Render AJAX Response Render
Step 2. AJAX
•
• Server Render
• redux-async-connect
• async-props
• React-Router onEnter API ( )
• universal-router
@fetchData((dispatch, state, routeState, replace) => {
return dispatch(getAllArticle());
})
class Home extends Component {
...
}
// fetchData(...)(Home)
<Route component={ App }>
<Route
path="/"
component={ Home }
onEnter={ Home.onEnter(store) }/>
</Route>
// fetchData.js
export default fetchCall => Component => {
Component.onEnter = (store) =>
(nextState, replace, callback) => {
const result = fetchCall(
store.dispatch,
store.getState(),
nextState,
replace) || Promise.resolve(true);
if(typeof window === 'undefined') {
result.then(() => callback())
.catch((error) => callback(error))
} else {
callback();
}
}
return Component;
}
Step 3.
• Server Render HTML JS
Client Render Client Render
Step 3.
•
• Server Render HTML
• Client Render
(initialState)
const store = createStore();
const childRoutes = createRoute(store);
match({
routes: childRoutes,
location: ctx.request.url
}, (error, redirectLocation, renderProps) => {
...
ctx.body = `<!DOCTYPE html> ... ${content}...
<script>
window.reduxState = ${JSON.stringify(store.getState())

</script>
</html>`
});
Step 4.
• SPA webpack JS
• css-loader
• url-loader
• NodeJS
Step 4.
•
• webpack bundle server code ( )
• js
•
• CSS Module css-modules-require-hook
var nodeExternals =
require('webpack-node-externals');
...
module.exports = {
...
target: 'node',
externals: [nodeExternals()]
...
};
Step 4 - Bundle node
• target node
• webpack-node-
externals
hint: context
Step 5.
• Server Client
• webpack
new webpack.DefinePlugin({
'process.env.BROWSER': true
}))
new webpack.DefinePlugin({
'process.env.BROWSER': false
}))
webpack-server.config.js webpack.config.js


Universal JavaScript


SEO First Time Loading
Universal JavaScript
MVC View
• MVC View
• HTML
• Universal JavaScript
• Client SPA View
Critical Render Path
Universal JavaScript
Universal JavaScript
Universal JavaScript
CSS Critical Render Path
• CSS
• Style head CSS
•
• Universal JavaScript
Universal JavaScript
• isomorphic-style-loader
• Render style head
for react-router: https://goo.gl/PYYoLL
Universal JavaScript
Universal JavaScript
Universal JavaScript
...
CSS Secret Lea Verou
CSS in JS ?
http://www.ituring.com.cn/article/261344
– Lea Verou, CSS Secret
If all you have is a hammer, everything looks like a nail.
Lea Verou


JavaScript
3D
HTML CSS
3D
CSS-Module
React-Native
3D
Universal JavaScript
Q&A
Ad

Recommended

You will learn RxJS in 2017
You will learn RxJS in 2017
名辰 洪
 
如何「畫圖」寫測試 - RxJS Marble Test
如何「畫圖」寫測試 - RxJS Marble Test
名辰 洪
 
RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術
名辰 洪
 
RxJS 5 in Depth
RxJS 5 in Depth
C4Media
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
 
rx.js make async programming simpler
rx.js make async programming simpler
Alexander Mostovenko
 
Debugging JavaScript with Chrome
Debugging JavaScript with Chrome
Igor Zalutsky
 
ES6 is Nigh
ES6 is Nigh
Domenic Denicola
 
History of jQuery
History of jQuery
jeresig
 
Ricky Bobby's World
Ricky Bobby's World
Brian Lonsdorf
 
Oop assignment 02
Oop assignment 02
MamoonKhan39
 
Compose Async with RxJS
Compose Async with RxJS
Kyung Yeol Kim
 
Angular2 rxjs
Angular2 rxjs
Christoffer Noring
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwift
Florent Pillet
 
Functional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwift
Rodrigo Leite
 
Javascript ES6 generators
Javascript ES6 generators
RameshNair6
 
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Jung Kim
 
Object-Oriented Javascript
Object-Oriented Javascript
kvangork
 
Reactive programming with RxSwift
Reactive programming with RxSwift
Scott Gardner
 
Expert JavaScript tricks of the masters
Expert JavaScript tricks of the masters
Ara Pehlivanian
 
The Promised Land (in Angular)
The Promised Land (in Angular)
Domenic Denicola
 
Reactive Programming with RxSwift
Reactive Programming with RxSwift
Scott Gardner
 
ES6 generators
ES6 generators
Steven Foote
 
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Aaron Douglas
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 
Understanding Functions and "this" in the World of ES2017+
Understanding Functions and "this" in the World of ES2017+
Bryan Hughes
 
ES6: The Awesome Parts
ES6: The Awesome Parts
Domenic Denicola
 
Building Web Apps with Express
Building Web Apps with Express
Aaron Stannard
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
scalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
Ngoc Dao
 

More Related Content

What's hot (19)

History of jQuery
History of jQuery
jeresig
 
Ricky Bobby's World
Ricky Bobby's World
Brian Lonsdorf
 
Oop assignment 02
Oop assignment 02
MamoonKhan39
 
Compose Async with RxJS
Compose Async with RxJS
Kyung Yeol Kim
 
Angular2 rxjs
Angular2 rxjs
Christoffer Noring
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwift
Florent Pillet
 
Functional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwift
Rodrigo Leite
 
Javascript ES6 generators
Javascript ES6 generators
RameshNair6
 
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Jung Kim
 
Object-Oriented Javascript
Object-Oriented Javascript
kvangork
 
Reactive programming with RxSwift
Reactive programming with RxSwift
Scott Gardner
 
Expert JavaScript tricks of the masters
Expert JavaScript tricks of the masters
Ara Pehlivanian
 
The Promised Land (in Angular)
The Promised Land (in Angular)
Domenic Denicola
 
Reactive Programming with RxSwift
Reactive Programming with RxSwift
Scott Gardner
 
ES6 generators
ES6 generators
Steven Foote
 
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Aaron Douglas
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 
Understanding Functions and "this" in the World of ES2017+
Understanding Functions and "this" in the World of ES2017+
Bryan Hughes
 
ES6: The Awesome Parts
ES6: The Awesome Parts
Domenic Denicola
 
History of jQuery
History of jQuery
jeresig
 
Compose Async with RxJS
Compose Async with RxJS
Kyung Yeol Kim
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwift
Florent Pillet
 
Functional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwift
Rodrigo Leite
 
Javascript ES6 generators
Javascript ES6 generators
RameshNair6
 
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Jung Kim
 
Object-Oriented Javascript
Object-Oriented Javascript
kvangork
 
Reactive programming with RxSwift
Reactive programming with RxSwift
Scott Gardner
 
Expert JavaScript tricks of the masters
Expert JavaScript tricks of the masters
Ara Pehlivanian
 
The Promised Land (in Angular)
The Promised Land (in Angular)
Domenic Denicola
 
Reactive Programming with RxSwift
Reactive Programming with RxSwift
Scott Gardner
 
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Aaron Douglas
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 
Understanding Functions and "this" in the World of ES2017+
Understanding Functions and "this" in the World of ES2017+
Bryan Hughes
 

Similar to Universal JavaScript (20)

Building Web Apps with Express
Building Web Apps with Express
Aaron Stannard
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
scalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
Ngoc Dao
 
Primefaces Nextgen Lju
Primefaces Nextgen Lju
Skills Matter
 
Primefaces Nextgen Lju
Primefaces Nextgen Lju
Skills Matter
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
Alona Mekhovova
 
React js
React js
Oswald Campesato
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortal
Jennifer Bourey
 
How and why i roll my own node.js framework
How and why i roll my own node.js framework
Ben Lin
 
ReactJS for Beginners
ReactJS for Beginners
Oswald Campesato
 
Angular or React
Angular or React
Orkhan Gasimov
 
Rack
Rack
shen liu
 
Server Side Swift: Vapor
Server Side Swift: Vapor
Paweł Kowalczuk
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
Loiane Groner
 
Clojure and the Web
Clojure and the Web
nickmbailey
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
Andrew Rota
 
Writing robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
Sam Brannen
 
Play vs Rails
Play vs Rails
Daniel Cukier
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
OdessaJS Conf
 
Building Web Apps with Express
Building Web Apps with Express
Aaron Stannard
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
scalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
Ngoc Dao
 
Primefaces Nextgen Lju
Primefaces Nextgen Lju
Skills Matter
 
Primefaces Nextgen Lju
Primefaces Nextgen Lju
Skills Matter
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
Alona Mekhovova
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortal
Jennifer Bourey
 
How and why i roll my own node.js framework
How and why i roll my own node.js framework
Ben Lin
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
Loiane Groner
 
Clojure and the Web
Clojure and the Web
nickmbailey
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
Andrew Rota
 
Writing robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
Sam Brannen
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
OdessaJS Conf
 
Ad

Recently uploaded (20)

Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Ad

Universal JavaScript