Old Gods & New: a vision of Backend & Frontend

140
Old Gods & New: A Vision of Backend & Frontend May 2015 By Gil Tayar

Transcript of Old Gods & New: a vision of Backend & Frontend

Page 1: Old Gods & New: a vision of Backend & Frontend

Old Gods & New: A Vision of Backend & FrontendMay 2015

By Gil Tayar

Page 2: Old Gods & New: a vision of Backend & Frontend

Chapter I: The Land of the Web

Page 3: Old Gods & New: a vision of Backend & Frontend
Page 4: Old Gods & New: a vision of Backend & Frontend
Page 5: Old Gods & New: a vision of Backend & Frontend

Paul

Page 6: Old Gods & New: a vision of Backend & Frontend

Two Tribes

Page 7: Old Gods & New: a vision of Backend & Frontend

The Backend Tribe

Page 8: Old Gods & New: a vision of Backend & Frontend

The Frontend Tribe

Page 9: Old Gods & New: a vision of Backend & Frontend

The Backend Gods

Page 10: Old Gods & New: a vision of Backend & Frontend

Thread Pools

Page 11: Old Gods & New: a vision of Backend & Frontend

Message Queues

Page 12: Old Gods & New: a vision of Backend & Frontend

Scala

Page 13: Old Gods & New: a vision of Backend & Frontend

And The Frontend Tribe?

Page 14: Old Gods & New: a vision of Backend & Frontend

Thread Pools

Page 15: Old Gods & New: a vision of Backend & Frontend

Message Queues

Page 16: Old Gods & New: a vision of Backend & Frontend

Scala

Page 17: Old Gods & New: a vision of Backend & Frontend

JavaScript

Page 18: Old Gods & New: a vision of Backend & Frontend

Angular

Page 19: Old Gods & New: a vision of Backend & Frontend

DOM

Page 20: Old Gods & New: a vision of Backend & Frontend

For they were old gods

Page 21: Old Gods & New: a vision of Backend & Frontend

Serving the Frontend Code

Page 22: Old Gods & New: a vision of Backend & Frontend

HTML

Page 23: Old Gods & New: a vision of Backend & Frontend

CSS

Page 24: Old Gods & New: a vision of Backend & Frontend

JavaScript

Page 25: Old Gods & New: a vision of Backend & Frontend

Please, pray to the backend gods

Page 26: Old Gods & New: a vision of Backend & Frontend

Thread PoolsMessage Queues

Scala

Page 27: Old Gods & New: a vision of Backend & Frontend

HTMLCSS

JavaScript

Page 28: Old Gods & New: a vision of Backend & Frontend

LET IT BE SO

Page 29: Old Gods & New: a vision of Backend & Frontend

FTP

Page 30: Old Gods & New: a vision of Backend & Frontend

HTML, CSS, JavaScript FTP⇒

Page 31: Old Gods & New: a vision of Backend & Frontend

Not Happy

Page 32: Old Gods & New: a vision of Backend & Frontend

http://mytribe.com/about-us.html

Page 33: Old Gods & New: a vision of Backend & Frontend

http://mytribe.com/about-us

Page 34: Old Gods & New: a vision of Backend & Frontend

Please, pray to the backend gods

Page 35: Old Gods & New: a vision of Backend & Frontend

Thread PoolsMessage Queues

Scala

Page 36: Old Gods & New: a vision of Backend & Frontend

And the backend tribe prayed

Page 37: Old Gods & New: a vision of Backend & Frontend

LET IT BE SO

Page 38: Old Gods & New: a vision of Backend & Frontend

URL Rewriting

Page 39: Old Gods & New: a vision of Backend & Frontend

Secret Sacred Server Configuration Files

Page 40: Old Gods & New: a vision of Backend & Frontend

And all was well

Page 41: Old Gods & New: a vision of Backend & Frontend

Chapter II: Serving ES6 Modules

Page 42: Old Gods & New: a vision of Backend & Frontend

Smitten with ES6 Modules

Page 43: Old Gods & New: a vision of Backend & Frontend
Page 44: Old Gods & New: a vision of Backend & Frontend
Page 45: Old Gods & New: a vision of Backend & Frontend

An ES6 Module

// aModule.jsexport function greet(name) { return 'hello ' + name;}

Page 46: Old Gods & New: a vision of Backend & Frontend

Importing ES6 Module

import {aFunction} from './aModule';

document.onready = function() {document.getElementById('greeting').

innerHTML = aFunction('anonymous');}

Page 47: Old Gods & New: a vision of Backend & Frontend

Who transpiles the ES6 toJavaScript?

Page 48: Old Gods & New: a vision of Backend & Frontend

babel

Page 49: Old Gods & New: a vision of Backend & Frontend

traceur

Page 50: Old Gods & New: a vision of Backend & Frontend

esnext

Page 51: Old Gods & New: a vision of Backend & Frontend

A Deep Hierarchy of ES6 Modules<script src= ></script>

Page 52: Old Gods & New: a vision of Backend & Frontend

The Sun Will Go DarkRequestmain.js

Responsemain.js

Requestsub-a.js

Responsesub-a.js

Requestsub-a-a.js

Responsesub-a-a.js

Page 53: Old Gods & New: a vision of Backend & Frontend

browserify

Page 54: Old Gods & New: a vision of Backend & Frontend

webpack

Page 55: Old Gods & New: a vision of Backend & Frontend

jspm

Page 56: Old Gods & New: a vision of Backend & Frontend

Bundling ES6 Modules

bundle.js

Page 57: Old Gods & New: a vision of Backend & Frontend
Page 58: Old Gods & New: a vision of Backend & Frontend

A month later...

Page 59: Old Gods & New: a vision of Backend & Frontend

The Wondrous F5( +R for all you Mac-ies)⌘

Page 60: Old Gods & New: a vision of Backend & Frontend

Bundling Kills Caching

bundle-for-page-1.js

Page 61: Old Gods & New: a vision of Backend & Frontend

Over-Bundling

bundle-for-page-2.js

bundle-for-page-1.js

Page 62: Old Gods & New: a vision of Backend & Frontend

Chapter III: The Bold Architecture

Page 63: Old Gods & New: a vision of Backend & Frontend
Page 64: Old Gods & New: a vision of Backend & Frontend

Backend Understanding JavaScript

bundle.js

Server

Page 65: Old Gods & New: a vision of Backend & Frontend

bundles killing caching?over-bundling?

Solved?

Page 66: Old Gods & New: a vision of Backend & Frontend
Page 67: Old Gods & New: a vision of Backend & Frontend

HTTP/2

Page 68: Old Gods & New: a vision of Backend & Frontend

HTTP/1Requestmain.js

Responsemain.js

Requestsub-a.js

Responsesub-a.js

Requestsub-b.js

Responsesub-b.js

Page 69: Old Gods & New: a vision of Backend & Frontend

To HTTP/2 Multi-ChannelRequestmain.js

Responsemain.js

Requestsub-a.js

Requestsub-b.js

Responsesub-a.js

Responsesub-b.js

Requestsub-b-a.js

Responsesub-a-b.js

Requestsub-a-b.js

Responsesub-b-a.js

Page 70: Old Gods & New: a vision of Backend & Frontend

HTTP/2 Push Mode

Request main.js

Response sub-a.js

Response sub-a-b.js

Response sub-b.js

Response sub-b-a.js

Page 71: Old Gods & New: a vision of Backend & Frontend

HTTP/2 Push Mode with Cache

Request main.js

Response sub-a.js

Response sub-a-b.js

Response sub-b.js

Response sub-b-a.js

Page 72: Old Gods & New: a vision of Backend & Frontend

“Please, plead to the gods about JavaScript and HTTP/2”

Page 73: Old Gods & New: a vision of Backend & Frontend

Thread PoolsMessage Queues

Scala

Page 74: Old Gods & New: a vision of Backend & Frontend
Page 75: Old Gods & New: a vision of Backend & Frontend
Page 76: Old Gods & New: a vision of Backend & Frontend
Page 77: Old Gods & New: a vision of Backend & Frontend

JavaScriptAngular

DOM

Page 78: Old Gods & New: a vision of Backend & Frontend
Page 79: Old Gods & New: a vision of Backend & Frontend

Chapter IV: CSS

Page 80: Old Gods & New: a vision of Backend & Frontend

HTML

Page 81: Old Gods & New: a vision of Backend & Frontend

CSS

Page 82: Old Gods & New: a vision of Backend & Frontend

JavaScript

Page 83: Old Gods & New: a vision of Backend & Frontend

Hm...

Page 84: Old Gods & New: a vision of Backend & Frontend

Do unto CSS, what you would do unto JavaScript?

Page 85: Old Gods & New: a vision of Backend & Frontend

Gods That Understand JS Give Us

● Auto-transpiling of ES6● Fast serving of JS modules● No cache-killing JS bundles● All using the wondrous F5 key

Page 86: Old Gods & New: a vision of Backend & Frontend

CSS

Page 87: Old Gods & New: a vision of Backend & Frontend
Page 88: Old Gods & New: a vision of Backend & Frontend
Page 89: Old Gods & New: a vision of Backend & Frontend

LESS

Page 90: Old Gods & New: a vision of Backend & Frontend

SASS

Page 91: Old Gods & New: a vision of Backend & Frontend

Compass

Page 92: Old Gods & New: a vision of Backend & Frontend

Better and Smaller CSS

Page 93: Old Gods & New: a vision of Backend & Frontend

Yes, CSS has modules

@import ‘sub.less';

...

Page 94: Old Gods & New: a vision of Backend & Frontend

Gods That Understand CSS Give Us

● Auto-transpiling of LESS● Fast serving of CSS modules● No cache-killing CSS bundles● All using the wondrous F5 key

Page 95: Old Gods & New: a vision of Backend & Frontend

“Please, plead to the gods about CSS and HTTP/2”

Page 96: Old Gods & New: a vision of Backend & Frontend

Thread PoolsMessage Queues

Scala

Page 97: Old Gods & New: a vision of Backend & Frontend
Page 98: Old Gods & New: a vision of Backend & Frontend
Page 99: Old Gods & New: a vision of Backend & Frontend

JavaScriptAngular

DOM

Page 100: Old Gods & New: a vision of Backend & Frontend

Chapter V: HTML and Caching

Page 101: Old Gods & New: a vision of Backend & Frontend

● Browser always checks if there is a new versiono Last-Modified/Etag

● Browser never checkso Expires: ∞

Browser Caching

Page 102: Old Gods & New: a vision of Backend & Frontend

Caching-Supportive HTML/JS

<script src="main-1.4.js">

Page 103: Old Gods & New: a vision of Backend & Frontend

Caching-Supportive HTML/JS

<script src="main.js">

Page 104: Old Gods & New: a vision of Backend & Frontend

Caching-Supportive HTML/JS

<script src="main-2014-06-08.js">

Page 105: Old Gods & New: a vision of Backend & Frontend

“Please, plead to the gods about HTML and infinity caching”

Page 106: Old Gods & New: a vision of Backend & Frontend

Thread PoolsMessage Queues

Scala

Page 107: Old Gods & New: a vision of Backend & Frontend
Page 108: Old Gods & New: a vision of Backend & Frontend

Pissed Off!

Page 109: Old Gods & New: a vision of Backend & Frontend
Page 110: Old Gods & New: a vision of Backend & Frontend

Chapter VI: Rendering HTML

Page 111: Old Gods & New: a vision of Backend & Frontend

Single Page Applications

Page 112: Old Gods & New: a vision of Backend & Frontend

Single Page Applications

Server

page.html

Service

xN times...

Page 113: Old Gods & New: a vision of Backend & Frontend

Server-side Rendering of HTML

Page 114: Old Gods & New: a vision of Backend & Frontend

SPA - New Gods Style

Server Service

rendercode

xN times...

page.html

Page 115: Old Gods & New: a vision of Backend & Frontend

SPA - New Gods Style

Server Service

rendercode

xN times...

page.html

Page 116: Old Gods & New: a vision of Backend & Frontend

The backend gods could execute JavaScript?

Page 117: Old Gods & New: a vision of Backend & Frontend

Sharing Frontend and Backend Code

Page 118: Old Gods & New: a vision of Backend & Frontend

Thread PoolsMessage Queues

Scala

Page 119: Old Gods & New: a vision of Backend & Frontend

“Please, plead to the gods about CSS and HTTP/2”

Page 120: Old Gods & New: a vision of Backend & Frontend
Page 121: Old Gods & New: a vision of Backend & Frontend
Page 122: Old Gods & New: a vision of Backend & Frontend

JavaScriptAngular

DOM

Page 123: Old Gods & New: a vision of Backend & Frontend
Page 124: Old Gods & New: a vision of Backend & Frontend
Page 125: Old Gods & New: a vision of Backend & Frontend
Page 126: Old Gods & New: a vision of Backend & Frontend

Message Queues

Page 127: Old Gods & New: a vision of Backend & Frontend

JavaScript

Page 128: Old Gods & New: a vision of Backend & Frontend

Hey, Great Idea

Page 129: Old Gods & New: a vision of Backend & Frontend

LET IT BE SO

Page 130: Old Gods & New: a vision of Backend & Frontend

Server

JS

● transpile ES6● minify JS● serve es6 modules

intelligently● cache es6 modules● ???

CSS

● transpile LESS● minify CSS● serve CSS modules

intelligently● cache CSS● ???

HTML

● Rewrite links for infinity expiring

● Render HTML server-side

● ???

Page 131: Old Gods & New: a vision of Backend & Frontend

The Frontend Tribe

Page 132: Old Gods & New: a vision of Backend & Frontend

Thread Pools

Page 133: Old Gods & New: a vision of Backend & Frontend

Message Queues

Page 134: Old Gods & New: a vision of Backend & Frontend

Scala

Page 135: Old Gods & New: a vision of Backend & Frontend

JavaScript

Page 136: Old Gods & New: a vision of Backend & Frontend

Angular

Page 137: Old Gods & New: a vision of Backend & Frontend

DOM

Page 138: Old Gods & New: a vision of Backend & Frontend

Seriously, though...

Page 139: Old Gods & New: a vision of Backend & Frontend

Frontend Platform

● Serving JS modules● Serving CSS modules● Transpiling CSS & JS● Infinity caching of JS & CSS● Server-side rendering of HTML● And who knows what else?

Page 140: Old Gods & New: a vision of Backend & Frontend

Thank You@giltayar