Slide 1

Slide 1 text

@CPHFRONT ⎯ @KSMANDERSEN

Slide 2

Slide 2 text

ISOMORPHIC WEB APPS

Slide 3

Slide 3 text

IN THE BEGINNING

Slide 4

Slide 4 text

AND THUS JAVASCRIPT WAS BORN

Slide 5

Slide 5 text

THE CRAZY ENGINEERS @ GOOGLE

Slide 6

Slide 6 text

LET'S RUN JAVASCRIPT ON SERVERS

Slide 7

Slide 7 text

ISOMORPHIC WEB APPS

Slide 8

Slide 8 text

UNIVERSAL WEB APPS

Slide 9

Slide 9 text

WHAT IT IS > An app that runs both on the server and the client > Rendering can be done both by the server and the browser > The apps share at least 90% of the same code

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

CLIENT-SIDE RENDERING > Rendering done client-side takes load away from the server > Consecutive page navigation is very fast > Fancy interactions, animations and rainbows

Slide 13

Slide 13 text

SERVER-SIDE RENDERING > More load on the server for rendering > Page content visible to bots, search engines and crazy people > The initial page load is faster (no app to boot client- side)

Slide 14

Slide 14 text

ISOMORPHIC RENDERING > The best of both worlds > Fast initial page load (server-side rendering) > Consecutive page loads are very fast (client-side rendering) > Page content visible for bots, search engines and crazy people

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

WHY IS REACT GREAT FOR ISOMORPHIC WEB APPS?

Slide 17

Slide 17 text

COMPONENTS COMPONENTS COMPONENTS

Slide 18

Slide 18 text

THE VIRTUAL DOM

Slide 19

Slide 19 text

await Router.dispatch({ path: req.path, query: req.query, context }, (state, component) => { data.body = ReactDOM.renderToString(component); });

Slide 20

Slide 20 text

DE-COUPLED ROUTING

Slide 21

Slide 21 text

const router = new Router(on => { on('*', async (state, next) => { const component = await next(); return component && {component}; }); on('/login', async () => ); });

Slide 22

Slide 22 text

EXPRESS.JS

Slide 23

Slide 23 text

const server = global.server = express(); server.get('*', async (req, res, next) => { res.status(200).send(`Hello World`); });

Slide 24

Slide 24 text

GREAT HOW DO I GET STARTED?

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

HOW IT ACTUALLY WORKS

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

SERVER.JS const server = global.server = express(); server.get('*', async (req, res, next) => { try { const data = { title: '', description: '', css: [], body: '', entry: assets.main.js }; const context = { insertCss: styles => data.css.push(styles._getCss()), ... }; await Router.dispatch({ path: req.path, query: req.query, context }, (state, component) => { data.body = ReactDOM.renderToString(component); data.css = css.join(''); }); const html = ReactDOM.renderToStaticMarkup(); res.status(200).send(`\n${html}`); } catch (err) { next(err); } }); server.listen(port, () => {});

Slide 29

Slide 29 text

DEMO TIME

Slide 30

Slide 30 text

@CPHFRONT ⎯ @KSMANDERSEN