better offline experience
play

Better offline experience Boyan Mihaylov @boyanio Internet speed - PowerPoint PPT Presentation

Better offline experience Boyan Mihaylov @boyanio Internet speed worldwide SLOWEST FASTEST @boyanio https://telegraphtravelmaps.carto.com/viz/b0a43e76-40bf-11e5-bfd4-0e6e1df11cbf/public_map @boyanio @boyanio Working while travelling


  1. Better offline experience Boyan Mihaylov @boyanio

  2. Internet speed worldwide SLOWEST FASTEST @boyanio https://telegraphtravelmaps.carto.com/viz/b0a43e76-40bf-11e5-bfd4-0e6e1df11cbf/public_map

  3. @boyanio

  4. @boyanio

  5. Working while travelling @boyanio https://www.wired.com/wp-content/uploads/blogs/wiredenterprise/wp-content/uploads/2013/09/docker-jungle.jpg

  6. Working while travelling @boyanio https://www.selectlegal.co.uk/wp-content/uploads/2015/07/Man-on-train.jpg

  7. @boyanio

  8. @boyanio

  9. “ Design your app to work offline, and it'll work beautifully all the time. Joanna Smith ” @boyanio

  10. Request- response revisited @boyanio

  11. @boyanio

  12. Request-response View View Network Controller @boyanio

  13. @boyanio

  14. Apply locally, sync with network View View Controller Model Network @boyanio

  15. @boyanio

  16. Persist model locally, sync with network View Application View Controller Logic Persistent Network Model @boyanio

  17. Network is your enemy, disk is your friend. @boyanio

  18. Service Workers A script running in the background Even when the browser is closed Acts as a proxy between the browser and the network (when available) Programmatic and controllable Cache API @boyanio

  19. Service Worker lifecycle Fetch / message Installing Activated Idle Terminated Error @boyanio

  20. Service Worker – register <script> if ("serviceWorker" in navigator) { navigator.serviceWorker.register("app-install.js") .then( function () { console.log("Service worker has been installed"); }, function (error) { console.log("Oops!", error); }); } else { console.log("No service workers support for this browser"); } </script> @boyanio

  21. Service Worker – install app-install.js const CACHE_NAME = "app.cache.v1"; this .addEventListener("install", (event) => { event.waitUntil( caches.open(CACHE_NAME).then((cache) => { return cache.addAll([ "/index.html", "/css/style.css", "/js/app.js" ]); }); ); }); … @boyanio

  22. Service Worker – fetch app-install.js … this .addEventListener("fetch", (event) => { event.respondWith( caches.match(event.request).then((response) => { return response || fetch(event.request); }); ); }); … @boyanio

  23. Service Worker specifics HTTPS only Asynchronous, promise-based No access to DOM Isn’t tied to a particular page Could work even if the browser is closed @boyanio

  24. Caching strategies using service workers @boyanio

  25. Network only 3 Scenarios • Analytics requests 1 2 www. • Non-GET requests @boyanio

  26. Cache only 3 Scenarios • The static part of your app 1 2 www. @boyanio

  27. Cache, falling back to network Scenarios 2 • The majority of requests 1 www. when building offline-first app 3 4 @boyanio

  28. Network, falling back to cache 4 Scenarios 3 • Online users will always 1 www. get the latest content • Offline users will get older 2 content @boyanio

  29. Cache & update 3 Scenarios 2 • You don’t mind showing 1 www. 4 old content for a while 2 @boyanio

  30. Cache, update, refresh 3 Scenarios 2 • Content that changes often 1 www. 4 (fx., game score, social media timeline) 2 4 @boyanio

  31. Network & cache race 3 Scenarios 2 • Small “non - important” 1 www. assets • Where performance 2 is vital 3 @boyanio

  32. “ There are only two hard things in Computer Science: cache invalidation and naming things. Phil Karlton ” @boyanio

  33. All I wanted was server workers @boyanio

  34. Are Service Workers ready? @boyanio https://caniuse.com/#feat=serviceworkers

  35. Act locally, sync globally Boyan Mihaylov @boyanio @boyanio

Recommend


More recommend