Save 37% off PRO during our Black Friday Sale! »

An Introduction to Service Workers - Gumtree Tech Talks

8ec1383b240b5ba15ffb9743fceb3c0e?s=47 Phil Nash
November 23, 2016

An Introduction to Service Workers - Gumtree Tech Talks

Service Workers are the biggest thing to hit the browser since XMLHttpRequest. We'll take a look at what the Service Worker can do for your app and more importantly, your users. We'll see the surprisingly small amount of code you need to get started with a Service Worker and finally we'll take a look at Progressive Web Apps and how the Service Worker will take part in a revolution for web applications.

Links:

Offline apps course on Udacity: https://www.udacity.com/course/offline-web-applications--ud899

The demo SMS app: https://github.com/philnash/sms-messages-app

HTML5Rocks intro to service worker: http://www.html5rocks.com/en/tutorials/service-worker/introduction/
Service Worker spec: https://slightlyoff.github.io/ServiceWorker/spec/service_worker/
Is Service Worker Ready Yet? https://jakearchibald.github.io/isserviceworkerready/
And resources: https://jakearchibald.github.io/isserviceworkerready/resources.html
Service Worker Cookbook: http://www.serviceworke.rs/
Addy Osmani - Offline Storage for Progressive Web Apps - https://bit.ly/cache-vs-db

Twilio Blog: Web powered SMS inbox with push notifications: https://www.twilio.com/blog/2016/02/web-powered-sms-inbox-with-service-worker-push-notifications.html
Background sync: https://developers.google.com/web/updates/2015/12/background-sync?hl=en

The Service Worker trailer: https://www.youtube.com/watch?v=QiXLaisCq10

8ec1383b240b5ba15ffb9743fceb3c0e?s=128

Phil Nash

November 23, 2016
Tweet

Transcript

  1. AN INTRODUCTION TO SERVICE WORKERS

  2. Phil Nash @philnash http://philna.sh philnash@twilio.com

  3. None
  4. AN INTRODUCTION TO SERVICE WORKERS

  5. SERVICE WORKERS ARE SCRIPTS THAT INTERCEPT NETWORK REQUESTS

  6. SO WEB DEVELOPERS CAN TREAT THE NETWORK AS AN ENHANCEMENT

  7. AND PROVIDE OFFLINE EXPERIENCES FOR USERS OF WEB APPLICATIONS

  8. None
  9. A SLIGHTLY LONGER INTRODUCTION TO SERVICE WORKERS

  10. XMLHttpRequest

  11. IN THE FUTURE WE WILL WONDER HOW WE COPED WITHOUT

    SERVICE WORKERS
  12. THE BIRTH OF THE SERVICE WORKER

  13. The Application Cache CACHE MANIFEST # Version 7 CACHE: #

    Stylesheets /style/app.css # JavaScripts /js/app.js 01. 02. 03. 04. 05. 06. 07. 08.
  14. “THE APPLICATION CACHE IS A DOUCHEBAG”

  15. The Spec https://slightlyoff.github.io/ServiceWorker/spec/service_worker/

  16. Browsers 40 27 44 4

  17. The other browsers? preview under consideration

  18. SO WHAT DOES IT REALLY DO?

  19. Install it navigator.serviceWorker.register("/sw.js");

  20. Install it navigator.serviceWorker.register("/sw.js", { scope: "/admin" }); 01. 02. 03.

  21. Install it navigator.serviceWorker.register("/sw.js").then(function(){ console.log(" "); }).catch(function(){ console.log(" "); }); 01.

    02. 03. 04. 05.
  22. It intercepts network requests // sw.js self.addEventListener("fetch", function(event) { //

    do something }); 01. 02. 03. 04.
  23. IT'S A PROXY THAT YOU CONTROL

  24. SECURITY?

  25. HTTPS

  26. LOCALHOST

  27. DEMO

  28. WHY?

  29. WEB VS NATIVE

  30. Native Web Online by default Offline by default Discoverable on

    the web App store installation
  31. Native Web Offline first Offline by default Discoverable on the

    web App store installation
  32. DON'T CARE FOR OFFLINE?

  33. PERFORMANCE

  34. FALLBACKS

  35. None
  36. PUSH NOTIFICATIONS

  37. DEMO

  38. Browsers 42 44 37 4

  39. WITH GREAT POWER…

  40. BACKGROUND SYNC

  41. DEMO

  42. Browsers 49

  43. GEOFENCING

  44. MAYBE...?

  45. PROGRESSIVE WEB APPS

  46. Progressive Web Apps •  Service Worker (+ HTTPS) •  manifest.json

    •  User engagement
  47. APP INSTALL BANNERS

  48. None
  49. ICON ON HOMESCREEN

  50. ...

  51. $$ PROFIT! $$

  52. SERVICE WORKERS

  53. ENHANCEMENT

  54. AN INTRODUCTION TO SERVICE WORKERS

  55. SERVICE WORKERS ARE SCRIPTS THAT INTERCEPT NETWORK REQUESTS

  56. SO WEB DEVELOPERS CAN TREAT THE NETWORK AS AN ENHANCEMENT

  57. AND PROVIDE OFFLINE EXPERIENCES FOR USERS OF WEB APPLICATIONS

  58. AND PROVIDE OFFLINE EXPERIENCES FOR USERS OF WEB APPLICATIONS

  59. AND PROVIDE BETTER EXPERIENCES FOR USERS OF WEB APPLICATIONS

  60. IN THE FUTURE WE WILL WONDER HOW WE COPED WITHOUT

    SERVICE WORKERS
  61. AND IF YOU'RE NOT YET CONVINCED...

  62. None
  63. THANKS!

  64. Thanks! @philnash http://philna.sh philnash@twilio.com