Slide 1

Slide 1 text

PROGRESSIVE WEB APPS in the real world

Slide 2

Slide 2 text

Dean Hume @deanohume

Slide 3

Slide 3 text

A Progressive Web App uses modern web capabilities to deliver an app-like user experience “

Slide 4

Slide 4 text

CORE DRIVERS

Slide 5

Slide 5 text

CORE DRIVERS URLS & Links

Slide 6

Slide 6 text

CORE DRIVERS URLS & Links System Capabilities

Slide 7

Slide 7 text

CORE DRIVERS URLS & Links Accessible System Capabilities

Slide 8

Slide 8 text

CORE DRIVERS URLS & Links Accessible System Capabilities Free!

Slide 9

Slide 9 text

These apps aren’t packaged and deployed through stores, they’re just websites that took all the right vitamins. Alex Russell “

Slide 10

Slide 10 text

Awesome

Slide 11

Slide 11 text

NO INSTALL NEEDED Awesome

Slide 12

Slide 12 text

NO INSTALL NEEDED NO DOWNLOAD Awesome

Slide 13

Slide 13 text

NO INSTALL NEEDED NO DOWNLOAD BUILT ON THE FABRIC OF THE WEB Awesome

Slide 14

Slide 14 text

You are already using them

Slide 15

Slide 15 text

What does this actually mean for our users?

Slide 16

Slide 16 text

What does this actually mean for our users? ★ More engaging

Slide 17

Slide 17 text

What does this actually mean for our users? ★ More engaging ★ Faster

Slide 18

Slide 18 text

What does this actually mean for our users? ★ More engaging ★ Faster ★ Reliable

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

This Talk

Slide 21

Slide 21 text

This Talk 1. Understanding Progressive Web Apps

Slide 22

Slide 22 text

This Talk 1. Understanding Progressive Web Apps 2. Engage your users

Slide 23

Slide 23 text

This Talk 1. Understanding Progressive Web Apps 2. Engage your users 3. Speed up your site

Slide 24

Slide 24 text

This Talk 1. Understanding Progressive Web Apps 2. Engage your users 3. Speed up your site 4. Improve reliability

Slide 25

Slide 25 text

Understanding progressive web apps 1

Slide 26

Slide 26 text

Service workers

Slide 27

Slide 27 text

Think of your web apps requests as planes taking off. ServiceWorker is the air traffic controller that routes the requests. Jeff Posnick “

Slide 28

Slide 28 text

“The perfect progressive enhancement.”

Slide 29

Slide 29 text

Behind the scenes

Slide 30

Slide 30 text

With Service Workers

Slide 31

Slide 31 text

With Service Workers

Slide 32

Slide 32 text

With Service Workers

Slide 33

Slide 33 text

With Service Workers

Slide 34

Slide 34 text

HTTPS Only

Slide 35

Slide 35 text

Free SSL

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Service Workers are the key to unlocking the power

Slide 38

Slide 38 text

Support

Slide 39

Slide 39 text

The Approach

Slide 40

Slide 40 text

The Approach App. Shell Architecture

Slide 41

Slide 41 text

The Approach Pick & Choose App. Shell Architecture

Slide 42

Slide 42 text

Application Shell Architecture

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

bit.ly/app-shell

Slide 45

Slide 45 text

Or pick & choose the features you like!

Slide 46

Slide 46 text

operasoftware.github.io/pwa-list

Slide 47

Slide 47 text

Summary ❖ Service Workers ❖ SSL only ❖ Architecture

Slide 48

Slide 48 text

2.Engage your users

Slide 49

Slide 49 text

2.1 Look and feel

Slide 50

Slide 50 text

2.1 Look and feel 2.2 Push notifications

Slide 51

Slide 51 text

2.1 Look and feel 2.3 Add to home screen 2.2 Push notifications

Slide 52

Slide 52 text

Look and feel

Slide 53

Slide 53 text

Look and feel

Slide 54

Slide 54 text

Look and feel bit.ly/color-custom

Slide 55

Slide 55 text

Manifest A simple JSON file that allows you to control how your app appears to the user

Slide 56

Slide 56 text

{ lang: "en", background_color: "#09adec", name: "Building Great Startup Teams", short_name: "Building Great Startup Teams", display: "standalone", icons: [ { src: "./images/logo-144.png", sizes: "144x144", type: "image/png" } ], start_url: "./index.html", orientation: "portrait" }

Slide 57

Slide 57 text

{ lang: "en", background_color: "#09adec", name: "Building Great Startup Teams", short_name: "Building Great Startup Teams", display: "standalone", icons: [ { src: "./images/logo-144.png", sizes: "144x144", type: "image/png" } ], start_url: "./index.html", orientation: "portrait" }

Slide 58

Slide 58 text

Customize

Slide 59

Slide 59 text

{ lang: "en", background_color: "#09adec", name: "Building Great Startup Teams", short_name: "Building Great Startup Teams", display: "standalone", icons: [ { src: "./images/logo-144.png", sizes: "144x144", type: "image/png" } ], start_url: "./index.html", orientation: "portrait" }

Slide 60

Slide 60 text

Slide 61

Slide 61 text

Manifest bit.ly/manifest-json

Slide 62

Slide 62 text

Manifest Generator tomitm.github.io/appmanifest

Slide 63

Slide 63 text

Push Notifications

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Three Steps 1. Subscribe User

Slide 66

Slide 66 text

Three Steps 1. Subscribe User 2. Save Subscription

Slide 67

Slide 67 text

Three Steps 1. Subscribe User 2. Save Subscription 3. Send from Google Cloud

Slide 68

Slide 68 text

Subscribe User

Slide 69

Slide 69 text

if ('serviceWorker' in navigator) { }

Slide 70

Slide 70 text

if ('serviceWorker' in navigator) { navigator.serviceWorker.register('service-worker.js').then(function (registration) { // Registration was successful }).catch(function(err) { // registration failed :( console.log('ServiceWorker registration failed: ', err); }); }

Slide 71

Slide 71 text

if ('serviceWorker' in navigator) { navigator.serviceWorker.register('service-worker.js').then(function (registration) { // Registration was successful registration.pushManager.subscribe({userVisibleOnly: true}) .then(function(subscription){ }); }).catch(function(err) { // registration failed :( console.log('ServiceWorker registration failed: ', err); }); }

Slide 72

Slide 72 text

Save Subscription

Slide 73

Slide 73 text

if ('serviceWorker' in navigator) { navigator.serviceWorker.register('service-worker.js').then(function (registration) { // Registration was successful registration.pushManager.subscribe({userVisibleOnly: true}) .then(function(subscription){ // Send to Server return sendSubscriptionToServer(subscription); }); }).catch(function(err) { // registration failed :( console.log('ServiceWorker registration failed: ', err); }); }

Slide 74

Slide 74 text

Send from Google Cloud

Slide 75

Slide 75 text

Manifest

Slide 76

Slide 76 text

{ "name": "Push Demo", "short_name": "Push Demo", "icons": [{ "src": "icon.png", "sizes": "192x192", "type": "image/png" }], "start_url": "/index.html", "display": "standalone", "gcm_sender_id": "57874135625436178", "gcm_user_visible_only": true, "permissions": [ "gcm" ]} Manifest

Slide 77

Slide 77 text

bit.ly/push-notifications-google bit.ly/push-notifications-dean Further reading

Slide 78

Slide 78 text

https://deanhume.github.io/typography

Slide 79

Slide 79 text

Add to home screen

Slide 80

Slide 80 text

Add to home screen

Slide 81

Slide 81 text

Add to home screen 1. You need a manifest.json file

Slide 82

Slide 82 text

Add to home screen 1. You need a manifest.json file 2. Your manifest file needs a start URL

Slide 83

Slide 83 text

Add to home screen 1. You need a manifest.json file 2. Your manifest file needs a start URL 3. You need a 144x144 PNG icon

Slide 84

Slide 84 text

Add to home screen 1. You need a manifest.json file 2. Your manifest file needs a start URL 3. You need a 144x144 PNG icon 4. Your site is using a Service Worker running over HTTPS

Slide 85

Slide 85 text

Add to home screen 1. You need a manifest.json file 2. Your manifest file needs a start URL 3. You need a 144x144 PNG icon 4. Your site is using a Service Worker running over HTTPS 5. The user has visited your site at least twice, with at least five minutes between visits.

Slide 86

Slide 86 text

{ lang: "en", background_color: "#09adec", name: "Building Great Startup Teams", short_name: "Building Great Startup Teams", display: "standalone", icons: [ { src: "./images/logo-144.png", sizes: "144x144", type: "image/png" } ], start_url: "./index.html", orientation: "portrait" }

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

Look and feel Add to home screen Push notifications Sum m ary

Slide 89

Slide 89 text

3.Speed up your site

Slide 90

Slide 90 text

3.1 Caching

Slide 91

Slide 91 text

3.1 Caching 3.2 Save-Data Header

Slide 92

Slide 92 text

3.1 Caching 3.3 Background Sync 3.2 Save-Data Header

Slide 93

Slide 93 text

Caching

Slide 94

Slide 94 text

With Service Workers

Slide 95

Slide 95 text

With Service Workers

Slide 96

Slide 96 text

var cacheVersion = 1; var currentCache = { assetCache: 'cache' + cacheVersion }; Caching

Slide 97

Slide 97 text

var cacheVersion = 1; var currentCache = { assetCache: 'cache' + cacheVersion }; this.addEventListener('install', event => { event.waitUntil(caches.open(currentCache.assetCache) .then(function(cache) { }) ); }); Caching

Slide 98

Slide 98 text

var cacheVersion = 1; var currentCache = { assetCache: 'cache' + cacheVersion }; this.addEventListener('install', event => { event.waitUntil(caches.open(currentCache.assetCache) .then(function(cache) { return cache.addAll(['result.min.css', './js/material.min.js']); }) ); }); Caching

Slide 99

Slide 99 text

var cacheVersion = 1; var currentCache = { assetCache: 'cache' + cacheVersion }; this.addEventListener('install', event => { event.waitUntil(caches.open(currentCache.assetCache) .then(function(cache) { return cache.addAll(['result.min.css', './js/material.min.js']); }) ); }); this.addEventListener('fetch', event => { event.respondWith(caches.match(event.request) .then(function (response) { return response || fetch(event.request); }) ); }); Caching

Slide 100

Slide 100 text

github.com/GoogleChrome/sw-toolbox bit.ly/sw-toolbox

Slide 101

Slide 101 text

Save-Data Header

Slide 102

Slide 102 text

Using Service Workers

Slide 103

Slide 103 text

Using Service Workers

Slide 104

Slide 104 text

this.addEventListener('fetch', event => { if(event.request.headers.get('save-data')){ if (/\.jpg$|.gif$|.png$/.test(event.request.url)) { // We can do something event.respondWith( fetch(‘low-quality-’ + event.request.url, { mode: 'no-cors' }) } } });

Slide 105

Slide 105 text

this.addEventListener('fetch', event => { if(event.request.headers.get('save-data')){ if (/\.jpg$|.gif$|.png$/.test(event.request.url)) { // We can do something event.respondWith( fetch(‘low-quality-’ + event.request.url, { mode: 'no-cors' }) } } });

Slide 106

Slide 106 text

this.addEventListener('fetch', event => { if(event.request.headers.get('save-data')){ if (/\.jpg$|.gif$|.png$/.test(event.request.url)) { // We can do something event.respondWith( fetch(‘low-quality-’ + event.request.url, { mode: 'no-cors' }) } } });

Slide 107

Slide 107 text

this.addEventListener('fetch', event => { if(event.request.headers.get('save-data')){ if (/\.jpg$|.gif$|.png$/.test(event.request.url)) { // We can do something event.respondWith( fetch(‘low-quality-’ + event.request.url, { mode: 'no-cors' }) } } });

Slide 108

Slide 108 text

buildingstartupteams.com

Slide 109

Slide 109 text

buildingstartupteams.com

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

Saved 900 KB!

Slide 112

Slide 112 text

Background sync

Slide 113

Slide 113 text

Using Service Workers

Slide 114

Slide 114 text

Using Service Workers

Slide 115

Slide 115 text

With Service Workers

Slide 116

Slide 116 text

Try later….

Slide 117

Slide 117 text

// Request a one-off sync: navigator.serviceWorker.ready.then( function(swRegistration) { return swRegistration.sync.register('myFirstSync'); });

Slide 118

Slide 118 text

// Request a one-off sync: navigator.serviceWorker.ready.then( function(swRegistration) { return swRegistration.sync.register('myFirstSync'); }); self.addEventListener('sync', function(event) { if (event.tag == 'myFirstSync') { event.waitUntil(expensiveOperation()); } });

Slide 119

Slide 119 text

// Request a one-off sync: navigator.serviceWorker.ready.then( function(swRegistration) { return swRegistration.sync.register('myFirstSync'); }); self.addEventListener('sync', function(event) { if (event.tag == 'myFirstSync') { event.waitUntil(expensiveOperation()); } });

Slide 120

Slide 120 text

Background sync bit.ly/background-sync

Slide 121

Slide 121 text

Caching Background Sync Save-Data Header Sum m ary

Slide 122

Slide 122 text

4.Reliable

Slide 123

Slide 123 text

4.1 Offline Browsing 4.2 3rd Party Scripts

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

Offline

Slide 126

Slide 126 text

With Service Workers

Slide 127

Slide 127 text

this.addEventListener('fetch', event => { };

Slide 128

Slide 128 text

this.addEventListener('fetch', event => { // Check if the user navigated if (event.request.method === 'GET' && event.request.headers. get('accept').includes('text/html')) { // Respond appropriately } };

Slide 129

Slide 129 text

this.addEventListener('fetch', event => { // Check if the user navigated if (event.request.method === 'GET' && event.request.headers. get('accept').includes('text/html')) { // Respond appropriately event.respondWith( fetch(event.request.url).catch(error => { // Return the offline page return caches.match('the-offline-page'); })); } };

Slide 130

Slide 130 text

Offline Applications bit.ly/offline-apps bit.ly/offline-page

Slide 131

Slide 131 text

3rd Party Scripts

Slide 132

Slide 132 text

Server Fails

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

Using Service Workers

Slide 135

Slide 135 text

Using Service Workers

Slide 136

Slide 136 text

With Service Workers

Slide 137

Slide 137 text

function timeout(delay) { return new Promise(function(resolve, reject) { setTimeout(function(){ resolve(new Response('', { status: 408, statusText: 'Request timed out.' })); }, delay); }); }

Slide 138

Slide 138 text

function timeout(delay) { return new Promise(function(resolve, reject) { setTimeout(function(){ resolve(new Response('', { status: 408, statusText: 'Request timed out.' })); }, delay); }); } self.addEventListener('fetch', event => { });

Slide 139

Slide 139 text

function timeout(delay) { return new Promise(function(resolve, reject) { setTimeout(function(){ resolve(new Response('', { status: 408, statusText: 'Request timed out.' })); }, delay); }); } self.addEventListener('fetch', event => { event.respondWith(Promise.race([timeout(6000), fetch (event.request.url)])); });

Slide 140

Slide 140 text

bit.ly/sw-timeout

Slide 141

Slide 141 text

Summary

Slide 142

Slide 142 text

Summary 1. Understanding Progressive Web Apps 2. Engage your users 3. Speed up your site 4. Improve reliability

Slide 143

Slide 143 text

Performance is a feature

Slide 144

Slide 144 text

Further reading ❖ Shell Architecture - bit.ly/instant-shell ❖ Getting Started - bit.ly/starting-pwas ❖ Service Worker - bit.ly/pwa-swers ❖ Code Labs -bit.ly/code-labs-pwa ❖ Recipes ➢ bit.ly/mozilla-service-workers ➢ bit.ly/chrome-service-workers

Slide 145

Slide 145 text

What’s still to come?

Slide 146

Slide 146 text

What’s still to come? Web Bluetooth webbluetoothcg.github.io/web-bluetooth Streams API jakearchibald.com/2016/streams-ftw Web NFC w3c.github.io/web-nfc Geofencing w3c.github.io/geofencing-api

Slide 147

Slide 147 text

Thank you! @ deanohum e