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

An Introduction to Service Workers - Code Europ...

Phil Nash
December 07, 2016

An Introduction to Service Workers - Code Europe Warsaw

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://github.com/w3c/ServiceWorker
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

Phil Nash

December 07, 2016
Tweet

More Decks by Phil Nash

Other Decks in Programming

Transcript

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

    Stylesheets /style/app.css # JavaScripts /js/app.js 01. 02. 03. 04. 05. 06. 07. 08.
  2. Native Web O ine rst O ine by default Discoverable

    on the web App store installation
  3. navigator.serviceWorker.register("/sw.js").then(function(reg) { console.log("Yay!"); reg.addEventListener("updatefound", function(){ var worker = reg.installing reg.installing.addEventListener("statechange",

    function(e) { if (worker.state == "installed") { worker.postMessage({action: "update"}); } }) }); }); 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11.
  4. var db = new Dexie("messageStore", { autoOpen: true }); db.version(1).stores({

    messages: "++,createdAt" }); 01. 02. 03. 04. 05. 06.
  5. db.transaction("w", db.messages, function() { db.messages.put({ from: FROM_NUMBER, to: TO_NUMBER, createAt:

    new Date(), body: "Service Workers rock " }).then(function(message){ console.log("Yay!"); }); }); 01. 02. 03. 04. 05. 06. 07. 08. 09. 10.