Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Isomorphic React: the benefits, pitfalls and work-arounds

Frontend NE
January 05, 2017

Isomorphic React: the benefits, pitfalls and work-arounds

For the layman, Isomorphic React is a server-rendered client side app. Got that? Us neither. Luckily Ali Sheehan-Dare is there to talk us all through it with an expansion on his post, A Lazy Isomorphic React Experiment.

Frontend NE

January 05, 2017
Tweet

More Decks by Frontend NE

Other Decks in Technology

Transcript

  1. • What is an isomorphic app? • Good things •

    Some code • Things to consider / difficulties Isomorphic React
  2. What is an isomorphic app? • An app which renders

    on the server initially, then continues to render on the client, using the same code. Client Server • Templates • Business logic • API Server-rendered codebase Isomorphic codebase Server Client Shared Client API Client-rendered codebase
  3. Why would we? “0.5 second delay caused a 20% drop

    in traffic” “100ms reduction in page load time increases revenue by 1%” - Google - Amazon
  4. Single Page App CLIENT SERVER Request page (HTML) Fetch js

    Initial render Fetch data (AJAX) Render with data First ‘paint’ (first tweet) 557ms * ✱ Average from DO London region, without browser caching - 157Kb bundle size Isomorphic App CLIENT SERVER Request page (HTML) Fetch js Begin rendering on client First ‘paint’ (first tweet) 376ms * Fetch data from API Send HTML JavaScript behaviour initialised: - Click listeners - Client side routing Generate HTML
  5. Client-only vs isomorphic rendering timings (with cache) 0 100 200

    300 400 500 600 0 100 200 300 400 500 600 700 800 900 Time (ms) Bundle size (Kb) Client (first paint) Isomorphic (first paint) Isomorphic (JavaScript enabled) $1,000,000,000
  6. Bot Visibility • Google crawler is not perfect! • What

    about non-Google crawlers? (Facebook, Twitter, etc…) http://www.doesgoogleexecutejavascript.com/
  7. • isomorphic-fetch or axios allows same data fetching code for

    both client and server • Both can request data from the same API server Fetching data Separate API server Client App code (components) • Initial HTML • App code React Rendering Server API Server API data API data
  8. • Rendering and API endpoints exist on same server •

    Either call – API endpoints on itself – Controller functions Fetching data One server Client App code (components) • Server-side Routing • Initial HTML • App code • API data Server Internal API requests
  9. Responsiveness App.js • Conditionally rendering elements depending on device type

    not reliable • Either guess or render nothing or mobile site
  10. • Many build features are more difficult in an isomorphic

    app – JS importing CSS – JS importing images – JavaScript styles - e.g. glamor • A solution – universal-webpack The Webpack battle
  11. • Can improve initial load time, bot visibility • Consider

    data fetching, responsiveness, build tools • Depends on your requirements To it up