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

Improving Media Content Performance with Servic...

Improving Media Content Performance with Service Workers #BuzzJS

The Next Billion Users are the next generation internet users and most of them have little outreach to strong internet resources. As developers, it's our responsibility to optimize, cache and deliver contents to them at all times (even when offline). This talk centers around the concepts of JavaScript Service Workers, browser caching for certain offline scenarios, and performance best practices to boost user conversion and experience.

Colin Bendell

June 15, 2018
Tweet

More Decks by Colin Bendell

Other Decks in Technology

Transcript

  1. 1 Service Workers & Media: for the rest of your

    users @ColinBendell CTO Office, Cloudinary
  2. JS PREACHER CHRISTIAN NWAMBA PROGRAM MANAGER / WRITER SCOTCH.IO DEV

    ADVOCATE / MARKETING CLOUDINARY ORGANIZER ANGULAR NIGERIA ORGANIZER FORLOOP AFRICA @codebeast AUTHOR
  3. “…25% of new Android phones have only 512MB of RAM.”

    Jen Fitzpatrick VP of product management for Google Maps
  4. Common Strategies • USSD / SMS • Accessibility • Research

    • Service Workers & PWA • Empathy @codebeast @colinbendell
  5. SW Basics • Persistent across page loads • Intercept Request

    & Response • Offline & Enhanced caching • Manifest: home icon, splash screen, standalone app @codebeast @colinbendell
  6. L1: 0.0005μs L2: 0.007μs L2: 0.030μs RAM: 0.1 μs SSD:

    0.15 ms Seek: 10 ms Wifi: 25ms LTE: 75ms 3G: 150ms 1 bit of data accessed from CPU, Memory, Disk, Network Caching is Everywhere (200x L1) (20,000,000x L1) (300,000,000x L1) (1,000,000,000x L1) (10,000,000,000x L1)
  7. • Image optimization • Progressive image delivery (use Intersection Observer)

    • Use bundle splitting • Deferred fetching with lazy loading • Prefetching • Take advantage of cache and web storage • Pretty much every other thing to make your web app fast and deliver better user experience
  8. addEventListener( 'fetch', ( fetchEvent ) => { if ( fetchEvent.request.destination

    !== 'image' ) { // console.log('not an image request'); return; } } );
  9. addEventListener( 'fetch', ( fetchEvent ) => { if ( fetchEvent.request.destination

    !== 'image' ) { // console.log('not an image request'); return; } const url = fetchEvent.request.url; fetchEvent.respondWith( fetch(url); ); } );
  10. addEventListener( 'fetch', ( fetchEvent ) => { if ( fetchEvent.request.destination

    !== 'image' ) { // console.log('not an image request'); return; } const url = fetchEvent.request.url; fetchEvent.respondWith( fetch( downscaled( url ) ); ); } );
  11. if ( // Save-Data is on fetchEvent.request.headers.get( 'save-data' ) //

    bandwidth or RTT is slower than a typical 3G connect || (navigator.connection.effectiveType.match( /2g/ ) ) // we have less than ~1GB of RAM || (navigator.deviceMemory < 1 ) ) {
  12. Source: Auth0 Flipkart 3x less data usage 40% higher re-engagement

    70% conversion rate @codebeast @colinbendell
  13. Source: Auth0 Housing.com 40% lower bounce rate 30% faster page

    load 10% longer avg session @codebeast @colinbendell
  14. Summary • We are technologists, you are not the typical

    user • Use Service Workers to adapt the User Experience • Offline Caching • Reduce pixel dimensions in fragile Networks