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

Next Gen Web: Scaling Progressive Web Apps

Next Gen Web: Scaling Progressive Web Apps

A case study of how we re-built Flipkart.com's desktop website as a progressive web app while dealing with the unique challenges of scaling to a new ecosystem without compromising on performance.

Abhinav Rastogi

September 15, 2016
Tweet

More Decks by Abhinav Rastogi

Other Decks in Technology

Transcript

  1. Typical SPA • Serve empty HTML from server • Client

    downloads JS bundle • Shows loaders, makes API calls • Renders full page • Subsequent navigations are client-side
  2. Typical SPA • Serve empty HTML from server • Client

    downloads JS bundle • Shows loaders, makes API calls • Renders full page • Subsequent navigations are client-side Pros: • Easy to implement • Fast navigations • Cheap server processing • Low server QPS
  3. Cons: • Empty page for a long time • SEO

    jeopardised • JS bundle is huge
  4. Upgrade #1 - App Shells Initial HTML renders ‘loading state’


    (Build-time rendering) Pros: • No more empty page!
  5. Update #2 - Server Render • Render full page on

    server for first request • Client loads JS, makes API calls • Re-renders complete page
  6. Update #2 - Server Render • Render full page on

    server for first request • Client loads JS, makes API calls • Re-renders complete page Pros: • First paint is meaningful • SEO is solved!
  7. Cons: • Significant increase in server load • HTML download

    size increased • Response time increased • JS file is still huge
  8. Update #3 - Universal app • Render only SEO-critical content

    on server • Client continues to work as normal • React is able to reconcile the DOM
  9. Update #3 - Universal app Pros: • Lesser load on

    server • Better SEO, smaller HTML • Header/Footer can load quicker :: Perceived perf! Cons: • First paint still slow • No organic content in first- paint • JS file is still huge
  10. Update #4 - First-fold Pros: • Making API calls from

    server is better • Organic content in first paint! • Send api data as part of HTML
  11. #5 - Route based chunking • Break JS bundle into

    parts based on routes • Only load JS required for the current page • Subsequent JS can be loaded when needed
  12. Break JS bundle? • Define “split-points” • Replace “import” with

    “require.ensure” • Webpack & React-Router take care of the rest!
  13. Update #6 - PRPL • Push critical resources for the

    initial route. • Render initial route. • Pre-cache remaining routes. • Lazy-load and create remaining routes on demand.
  14. #7 - HTML streaming • Some parts of html are

    independent of page type/ url. Send those first to start resource download • Smart use of preload, prefetch and defer!
  15. Pros: • CSS and JS resources can start downloading within

    milliseconds of request • Page is ready to render as soon as HTML is downloaded Cons: • Server has to keep connection open with client until download completes • Client can download limited number of resources at a time
  16. Track custom perf events • Existing browser events like DOMContentLoaded

    and Load are not sufficient • Track real first-paint using RAF and User Timing API • More custom metrics?
  17. Key Take-aways • Problems and solutions are different for Mobile

    and Desktop • Treat performance as a feature • You can’t optimise what you can’t measure • You can split JS bundles into smaller chunks • Smart preloading of chunks goes a long way • RUM is important. Synthetic testing can only do so much.