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

San Diego JS - Progressive Web Apps

San Diego JS - Progressive Web Apps

Brian Cardarella

June 08, 2016
Tweet

More Decks by Brian Cardarella

Other Decks in Technology

Transcript

  1. “It’s not an easy time to build consumer facing mobile

    companies. It is not an easy time to invest in them either.” — Fred Wilson
 Union Square Ventures
  2. However… The User Experience Sucks because… • no home screen

    apps • no offline mode support • they’re slow
  3. Progressive Web Apps (PWA) • Instant loading • Fast •

    Offline / Lie-fi mode • Add to Home Screen • Secure • Push Notifications • Responsive
  4. • Users time on site with Flipkart lite vs. previous

    mobile experience: 3.5 minutes vs 70 seconds • 3x more time spent on site • 40% higher re-engagement rate • 70% greater conversion rate among those arriving via Add to Homescreen • 3x lower data usage
  5. • 92% less data for initial load, vs. native app

    • 82% less data to complete first transaction, vs. native app • 63% less data for initial load, vs. previous mobile web experience • 84% less data to complete first transaction, vs. previous mobile web experience
  6. serviceWorker var offlineFundamentals = [ '/', '/offline', '/css/all.css', '/js/all.js' ];

    self.addEventListener('install', function installer (event) { event.waitUntil( caches .open('v1::fundamentals') .then(function prefill (cache) { return cache.addAll(offlineFundamentals); }) ); }); https://ponyfoo.com/articles/serviceworker-revolution
  7. fetch replacing XMLHttpRequest function reqListener () { console.log(this.responseText); } var

    req = new XMLHttpRequest(); req.addEventListener("load", reqListener); req.open("GET", "http://www.example.org/example.txt"); oReq.send();
  8. fetch var myHeaders = new Headers(); var myInit = {

    method: 'GET', headers: myHeaders, mode: 'cors', cache: 'default' }; var myRequest = new Request(‘flowers.jpg', myInit); fetch(myRequest, myInit) .then(function(response) { return response.blob(); }); https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
  9. serviceWorker self.addEventListener('fetch', function fetcher (event) { var request = event.request;

    if (request.method !== 'GET') { event.respondWith(fetch(request)); return; } // handle other requests }); https://ponyfoo.com/articles/serviceworker-revolution
  10. serviceWorker self.addEventListener('fetch', function fetcher (event) { var request = event.request;

    if (request.method !== 'GET') { event.respondWith(fetch(request)); return; } event.respondWith(caches .match(request) .then(queriedCache); ); }); https://ponyfoo.com/articles/serviceworker-revolution
  11. https://ponyfoo.com/articles/serviceworker-revolution function queriedCache (cached) { var networked = fetch(request) .then(fetchedFromNetwork,

    unableToResolve) .catch(unableToResolve); return cached || networked; } function fetchedFromNetwork (response) { var clonedResponse = response.clone(); caches.open(version + 'pages').then(function add (cache) { cache.put(request, clonedResponse); }); return response; } function unableToResolve () { return new Response('', { status: 503, statusText: 'Service Unavailable' }); }
  12. Conclusion •PWAs allow you to compete with native • PWAs

    will make you more money •PAWs will save you money •PWAs are easy to get started •PWAs are very powerful •PWAs can save the mobile web