Isomorphic Apps
What is
Isomorphic
JavaScript?
JavaScript code that can be shared between
environments.
i·so·mor·phic
same form
Persistence
Client
JavaScript
DOM manipulation UX
View layer
Application
logic
Routing
Backend
Ruby
Python
Java
PHP
Old Web Apps
Backend
Ruby
Python
Java
PHP
Persistence
Client
JavaScript
DOM manipulation UX
View layer
Application
logic
Routing
Fat-Client
Persistence
Client
JavaScript
Shared
JavaScript
View layer
Application
logic
Routing
DOM manipulation UX
Backend
Ruby
Python
Java
PHP
Isomorphic
Why go to the trouble?
Performance
Performance
Initial pageload
speed.
SEO
Crawlable single-page
apps.
Flexibility
Run code anywhere.
Client-rendered app
User sees
content
Exacerbated on mobile: high
latency, low bandwidth
Download
skeleton
HTML
Download
JavaScript
Evaluate
JavaScript
Fetch data
from API
Server-rendered app
Download
full
HTML
Download
JavaScript
User sees
content
Evaluate
JavaScript
How to Isomorph
Isomorphic JavaScript can
be environment agnostic
or
shimmed per environment.
Environment
agnostic
Does not depend on browser-specific
properties (window) or server-specific
properties (process.env,
req.cookies).
Shimmed
per
environment
window.location.pathname
vs
req.path
Module can expose a single API. But
does different things on server/browser.
How we do/did it!
ReactDOMServer.renderToString
Normal Router
Router for server
rendering
Server rendering is a bit different than in a client because you'll
want to:
Send 500 responses for errors
Send 30x responses for redirects
Fetch data before rendering (and use the router to help you do
it)
To facilitate these needs, you drop one level lower than the
<Router> API with:
match to match the routes to a location without rendering
RouterContext for synchronous rendering of route components
Isomorphic Router
Will be used by both server and client.
And finally…
The STORE!!!!
Server side
● Create store and initialize it to default values.
● Do the initial on load dispatches as required
by components.(which might or might not
change the store values)
● Assign the store values as window variables
in the html passed to client
Client Side
● Initialize store again with the window variable
supplied by server
The End.

Isomorphic apps