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

An Introduction to Service Workers - Refresh 2016

8ec1383b240b5ba15ffb9743fceb3c0e?s=47 Phil Nash
September 09, 2016

An Introduction to Service Workers - Refresh 2016

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

8ec1383b240b5ba15ffb9743fceb3c0e?s=128

Phil Nash

September 09, 2016
Tweet

Transcript

  1. AN INTRODUCTION TO SERVICE WORKERS

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

  3. AN INTRODUCTION TO SERVICE WORKERS

  4. SERVICE WORKERS ARE SCRIPTS THAT INTERCEPT NETWORK REQUESTS

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

  6. AND PROVIDE OFFLINE EXPERIENCES FOR USERS OF WEB APPLICATIONS

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

  9. XMLHttpRequest

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

    SERVICE WORKERS
  11. THE BIRTH OF THE SERVICE WORKER

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

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

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

  15. Browsers 40 27 44 4

  16. The other browsers? preview under consideration

  17. SO WHAT DOES IT REALLY DO?

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

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

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

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

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

  23. SECURITY?

  24. HTTPS

  25. LOCALHOST

  26. DEMO

  27. WHY?

  28. WEB VS NATIVE

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

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

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

  32. PERFORMANCE

  33. FALLBACKS

  34. None
  35. PUSH NOTIFICATIONS

  36. DEMO

  37. Browsers 42 44 37 4

  38. WITH GREAT POWER…

  39. BACKGROUND SYNC

  40. DEMO

  41. Browsers 49

  42. GEOFENCING

  43. MAYBE...?

  44. PROGRESSIVE WEB APPS

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

    • User engagement
  46. APP INSTALL BANNERS

  47. None
  48. ICON ON HOMESCREEN

  49. ...

  50. $$ PROFIT! $$

  51. SERVICE WORKERS

  52. ENHANCEMENT

  53. AN INTRODUCTION TO SERVICE WORKERS

  54. SERVICE WORKERS ARE SCRIPTS THAT INTERCEPT NETWORK REQUESTS

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

  56. AND PROVIDE OFFLINE EXPERIENCES FOR USERS OF WEB APPLICATIONS

  57. AND PROVIDE OFFLINE EXPERIENCES FOR USERS OF WEB APPLICATIONS

  58. AND PROVIDE BETTER EXPERIENCES FOR USERS OF WEB APPLICATIONS

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

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

  61. 0:00 / 1:13

  62. THANKS!

  63. None
  64. Use the code PNASH20 for 20% off ticket prices

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