Gleb Bahmutov PRO
JavaScript ninja, image processing expert, software quality fanatic
source: http://www.slideshare.net/Hugeinc/javascript-state-of-the-union-2015-english
Angular vs React: there will be blood
Every "X is faster than Y" comparison
Joe Gregorio - No more JS frameworks
"Web Workers" by Nolan Lawson @nolanlawson, EmpireJS 2016
Page runs in a single thread - everything is competing for 1/60 of a second
Source: http://www.pocketjavascript.com/blog/2015/11/23/introducing-pokedex-org
main.js | 24 kB |
worker.js | 90 kB |
serviceWorker.js | 16 kB |
by Henrik Joreteg
code coverage proxy was-tested
// calc.js
export const add = (a, b) => a + b
export const sub = (a, b) => a - b
// main.js
import { add } from './calc'
...
// bundle.js
const add = (a, b) => a + b
...
rollup main.js
Using CDN, parallel downloads, caching, small images, above the fold, etc.
HTML
JS
CSS
HTML
JS
CSS
Framework
HTML
JS
CSS
Framework
app
HTML
JS
CSS
Framework
app
get data
HTML
JS
CSS
Framework
app
draw
get data
HTML
JS
CSS
Framework
app
draw
get data
HTML
Cached by the browser
You should cache
JS
CSS
Framework
app
draw
get data
HTML
This part can be expensive!
startup
PivotalTracker reloading without data changes
- Initial HTML loads
- Application code loads
<html>
<script src="app.js"></script>
<body>
<h1>My awesome app</h1>
<div id="app"></div>
<footer>...</footer>
</body>
</html>
- App loads data
- App updates page
<html>
<script src="app.js"></script>
<body>
<h1>My awesome app</h1>
<div id="app"></div>
<footer>...</footer>
</body>
</html>
- App loads data
- App updates page
Sudden change in the page!
<html>
<script src="app.js"></script>
<body>
<h1>My awesome app</h1>
<div id="app">
<ul>
<li>Clean my room</li>
<li>Learn Italian</li>
<li>Finish the slides</li>
</ul>
</div>
<footer>...</footer>
</body>
</html>
source:Â glebbahmutov.com/hydrate-vue-todo/Â (no hydration)
app
HTML
data
load
load
render
app
HTML
data
load
load
render
source: glebbahmutov.com/hydrate-vue-todo/Â (with hydration)
Single small JS library bahmutov/hydrate-app
<div id="app">
...
</div>
<script src="hydrate-app.js" id="app"></script>
Works with any web framework
// hydrate-app gives you window.bottle
bottle.drink() // app has loaded and ready to take over
bottle.refill() // save DOM for next reload
There is a flash
<body>
<header>...</header>
<div id="app"></div>
<script src="hydrate-app.js"></script>
</body>
const html = localStorage.get ...
$('#app').innerHTML = '...'
Self-rewriting page is never going to be as smooth as server-side rendering
browser
ServiceWorker
<html>
<body>
<header>...</header>
<div id="app">
<ul>
<li>Clean my room</li>
...
</ul>
</div>
<footer>...</footer>
</body>
</html>
<ul>
<li>Clean my room</li>
...
</ul>
Cache
Server
browser
ServiceWorker
<html>
<body>
<header>...</header>
<div id="app"></div>
<footer>...</footer>
</body>
</html>
<html>
<body>
<header>...</header>
<div id="app">
<ul>
<li>Clean my room</li>
...
</ul>
</div>
<footer>...</footer>
</body>
</html>
<ul>
<li>Clean my room</li>
...
</ul>
Cache
Inserts cached HTML fragment into response body HTML
reload()
self.addEventListener('fetch', function (event) {
event.respondWith(
fetch(event.request)
.then(function (response) {
// merge HTML
var responseOptions = {
status: 200,
headers: {
'Content-Type': 'text/html charset=UTF-8'
}
}
return new Response(resultHtml, responseOptions)
})
)
})
Works with any web framework
API
server
database
API
server
database
replication
server
database
database
Web app only works with in-browser PouchDB
PouchDB can synch with another PouchDB / CouchDB / *
replication
server
database
database
PouchDB can synch when a connection is available
replication
server
database
database
replication
server
database
database
Hoodie API for offline web apps rocks
hoodie
event analysis and statistics for financial markets
Boston and New York
data
finished?
$http.get(...).then(...)
finished?
$http.get(...).then(...)
.then(...)
* times
stream
stream operation
* times
stream
stream
stream
RxJS for the win!
stream
stream
function add(a, b) {
return a + b
}
Remember pure functions?
Simple to write
Simple to test
Simple to reuse
const F = compose(f, g, h)
F(x)
Can a web application be pure?
function main() {
window.title = 'hi'
}
function main() {
const title = 'hi'
return function foo() {
window.title = title
}
}
// pure
// dirty
const app = main()
app()
// pure
// dirty
function main(win) {
const title = 'hi'
return function foo() {
win.title = title
}
}
// pure
// dirty
const app = main(window)
app()
// pure
// dirty
function main({DOM}) {
const keyups$ = DOM.select(...)
return {
DOM: keyups$.map(...vdom...)
}
}
all inputs are streams
all outputs are streams
function main({DOM}) {
const keyups$ = DOM.select(...)
return {
DOM: keyups$.map(...vdom...)
}
}
Backbone
Angular 1
React
Angular 1
that makes your team more productive and happy
By Gleb Bahmutov
Should I learn and use Angular 1, React, Angular 2, Ember or something else? What are the common features they all share? How are they different? Are there "better" frameworks that will be popular next year? I will show a couple of new approaches that should be part of any future-proof framework: reactive streams for managing the data flow, virtual DOM abstractions for speed, testability and performance tools built right into the framework. The presentation might be controversial, but the struggle to pick "the next best thing" is very real. Video at https://www.youtube.com/watch?v=ji8hqDi2BnA
JavaScript ninja, image processing expert, software quality fanatic