Slide 1

Slide 1 text

Proprietary + Confidential Progressive Web Apps Mobile has natively come to the Web Surma @DasSurma

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Bach's home page h1 { color: red }

Bach's home page

Johann Sebastian Bach was a prolific composer.

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Ajax was born to run desktop apps on the Web

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

How did the Web beat native applications on the desktop?

Slide 9

Slide 9 text

Distribution Is The Hardest Problem In Software flickr.com/photos/blakespot/

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

What if the Web evolved those capabilities, just as it did with Ajax?

Slide 12

Slide 12 text

Got Service Workers? and HTTPS?

Slide 13

Slide 13 text

Service Workers Are Network Progressive Enhancement A Programmable Network Proxy under your control.

Slide 14

Slide 14 text

Service Workers are to Progressive Web Apps as XMLHttpRequest was to Ajax The foundational capability that was a tipping point for innovation

Slide 15

Slide 15 text

What's Missing? 1. Homescreen Access 2. Push Notifications 3. Offline

Slide 16

Slide 16 text

1. Homescreen Access Less typing, more tapping.

Slide 17

Slide 17 text

airhorner.com Paul Kinlan @paulkinlan

Slide 18

Slide 18 text

2007: iPhone launch

Slide 19

Slide 19 text

Installable // Later on more icon sizes.... // Nice splash screen ...

Slide 20

Slide 20 text

Launch like an app (no address bar)

Slide 21

Slide 21 text

Offline available db = openDatabase("Todo", "1", "Todo", 5 * 1024 * 1024); db.transaction(function(tx) { tx.executeSql("SELECT * FROM CARS)"); }); App Cache Web SQL

Slide 22

Slide 22 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem We have everything we need?

Slide 23

Slide 23 text

2012: Early Chrome on Android

Slide 24

Slide 24 text

Standardised Add to homescreen

Slide 25

Slide 25 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Installable web apps in 2 simple steps { "name": "The Airhorner", "short_name": "Airhorner", "icons": [], "start_url": "index.html", "display": "standalone", "theme_color": "", "background_color": "" } 1. Create a manifest (json) 2. Link it to your page

Slide 26

Slide 26 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Flow 1. User clicks “Add to home screen” a. Manifest is downloaded 2. Confirmation prompt shown 3. You are on the homescreen

Slide 27

Slide 27 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Flow 1. User clicks “Add to home screen” a. Manifest is downloaded 2. Confirmation prompt shown 3. You are on the homescreen

Slide 28

Slide 28 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Flow 1. User clicks “Add to home screen” a. Manifest is downloaded 2. Confirmation prompt shown 3. You are on the homescreen

Slide 29

Slide 29 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Flow { "name": "The Air Horner", "short_name": "Air Horner", "icons": [ { "src": "images/Airhorner_192.png", "type": "image/png", "sizes": "192x192" } ], "start_url": "index.html", "display": "standalone", "theme_color": "#2196F3", "background_color": "#2196F3" }

Slide 30

Slide 30 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Homescreen { "name": "The Air Horner", "short_name": "Air Horner", "icons": [ { "src": "images/Airhorner_192.png", "type": "image/png", "sizes": "192x192" } ], "start_url": "index.html", "display": "standalone", "theme_color": "#2196F3", "background_color": "#2196F3" }

Slide 31

Slide 31 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem App switcher { "name": "The Air Horner", "short_name": "Air Horner", "icons": [ { "src": "images/Airhorner_192.png", "type": "image/png", "sizes": "192x192" } ], "start_url": "index.html", "display": "standalone", "theme_color": "#2196F3", "background_color": "#2196F3" }

Slide 32

Slide 32 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Splash screen: part 1 { "name": "The Air Horner", "short_name": "Air Horner", "icons": [ { "src": "images/Airhorner_192.png", "type": "image/png", "sizes": "192x192" } ], "start_url": "index.html", "display": "standalone", "theme_color": "#2196F3", "background_color": "#2196F3" }

Slide 33

Slide 33 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem What to Launch { "name": "The Air Horner", "short_name": "Air Horner", "icons": [ { "src": "images/Airhorner_192.png", "type": "image/png", "sizes": "192x192" } ], "start_url": "index.html?homescreen", // stats.... "display": "standalone", "theme_color": "#2196F3", "background_color": "#2196F3" }

Slide 34

Slide 34 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Splash screen: part 2 { "name": "The Air Horner", "short_name": "Air Horner", "icons": [ { "src": "images/Airhorner_192.png", "type": "image/png", "sizes": "192x192" } ], "start_url": "index.html", "display": "standalone", "theme_color": "#2196F3", "background_color": "#2196F3" }

Slide 35

Slide 35 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem How to launch: standalone { "name": "The Air Horner", "short_name": "Air Horner", "icons": [ { "src": "images/Airhorner_192.png", "type": "image/png", "sizes": "192x192" } ], "start_url": "index.html", "display": "standalone", "theme_color": "#2196F3", "background_color": "#2196F3" }

Slide 36

Slide 36 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem How to launch: window { "name": "The Air Horner", "short_name": "Air Horner", "icons": [ { "src": "images/Airhorner_192.png", "type": "image/png", "sizes": "192x192" } ], "start_url": "index.html", "display": "standalone", // window "theme_color": "#2196F3", "background_color": "#2196F3" }

Slide 37

Slide 37 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Tailor user interface if (window.matchMedia('(display-mode: standalone)').matches) { console.log("Thank you for installing our app!"); } @media all and (display-mode: standalone) { body { background-color: yellow; } }

Slide 38

Slide 38 text

It’s great, but... Native apps can prompt the user to install... Proprietary + Confidential

Slide 39

Slide 39 text

Prompt to Install

Slide 40

Slide 40 text

Prompting the user is a powerful feature Only sites the browser thinks the user will want to re-engage with will get the prompt

Slide 41

Slide 41 text

Offer an offline experience Have a manifest User is engaged Follow Jake’s guidance. ● Service Worker ● HTTPS Define what to launch and how to launch it. 2 “navigations” within at least 5 minutes* * this will change

Slide 42

Slide 42 text

Why so strict?

Slide 43

Slide 43 text

No offline-o-saurus. When you are on the user’s Home screen, you should always be available

Slide 44

Slide 44 text

Why manifest? Don’t launch into a leaf page You need to control the launch experience

Slide 45

Slide 45 text

Why engaged? Don’t spam the users

Slide 46

Slide 46 text

Can I control it?

Slide 47

Slide 47 text

Yes onbeforeinstallprompt

Slide 48

Slide 48 text

Suppress prompt window.addEventListener("beforeinstallprompt", (e) => e.preventDefault() );

Slide 49

Slide 49 text

Defer to a later time var deferredEvent; window.addEventListener("beforeinstallprompt", (e) => { e.preventDefault(); deferredEvent = e; // show install button } ); button.addEventListener("click", (e) => deferredEvent.prompt(); );

Slide 50

Slide 50 text

Defer to a later time var deferredEvent; window.addEventListener("beforeinstallprompt", (e) => { e.preventDefault(); deferredEvent = e; // show install button } ); button.addEventListener("click", (e) => deferredEvent.prompt(); );

Slide 51

Slide 51 text

Understand the user’s choice var deferredEvent; window.addEventListener("beforeinstallprompt", (e) => e.prompt().then((r) => r.userChoice) .then((c) => { if(c.choice == "installed") { // Success } else { // The user cancelled } }) );

Slide 52

Slide 52 text

2. Push Notifications How can we re-engage users at the right time?

Slide 53

Slide 53 text

26% increase in average spend per visit by members arriving via a push notification 72% increase in time spent for users visiting via a push notification +50% repeat visits within 3 months

Slide 54

Slide 54 text

Proprietary + Confidential

Slide 55

Slide 55 text

Add Project ID to the Manifest.json { "short_name": "Air Horner", "name": "Air Horner", "start_url": "/", "display": "standalone", "icons": [{ "src": "icons/icon-192.png", "sizes": "192x192", "type": "image/png" }], "gcm_sender_id": "123456789012345" }

Slide 56

Slide 56 text

Add Project ID to the Manifest.json { "short_name": "Air Horner", "name": "Air Horner", "start_url": "/", "display": "standalone", "icons": [{ "src": "icons/icon-192.png", "sizes": "192x192", "type": "image/png" }], "gcm_sender_id": "123456789012345" }

Slide 57

Slide 57 text

Setup work for Firefox [This space intentionally blank]

Slide 58

Slide 58 text

Proprietary + Confidential On the Client

Slide 59

Slide 59 text

Checking for subscriptions if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/service-worker.js') .then(function(reg) { reg.pushManager.getSubscription() .then(function(sub) { console.log('Subscription Info', sub); }); }); } else { console.log('Subscription Info', 'Not Supported'); }

Slide 60

Slide 60 text

Checking for subscriptions if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/service-worker.js') .then(function(reg) { reg.pushManager.getSubscription() .then(function(sub) { console.log('Subscription Info', sub); }); }); } else { console.log('Subscription Info', 'Not Supported'); }

Slide 61

Slide 61 text

Checking for subscriptions if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/service-worker.js') .then(function(reg) { reg.pushManager.getSubscription() .then(function(sub) { console.log('Subscription Info', sub); }); }); } else { console.log('Subscription Info', 'Not Supported'); }

Slide 62

Slide 62 text

Requesting permission and subscribing function subscribe() { navigator.serviceWorker.getRegistration().then(function(reg) { reg.pushManager.subscribe({userVisibleOnly: true}) .then(function(sub) { console.log('Update Server with End Point', sub); }).catch(function(error) { console.log('Unable to subscribe user', error); }); }); }

Slide 63

Slide 63 text

Requesting permission and subscribing function subscribe() { navigator.serviceWorker.getRegistration().then(function(reg) { reg.pushManager.subscribe({userVisibleOnly: true}) .then(function(sub) { console.log('Update Server with End Point', sub); }).catch(function(error) { console.log('Unable to subscribe user', error); }); }); }

Slide 64

Slide 64 text

Requesting permission and subscribing function subscribe() { navigator.serviceWorker.getRegistration().then(function(reg) { reg.pushManager.subscribe({userVisibleOnly: true}) .then(function(sub) { console.log('Update Server with End Point', sub); }).catch(function(error) { console.log('Unable to subscribe user', error); }); }); }

Slide 65

Slide 65 text

Requesting permission and subscribing function subscribe() { navigator.serviceWorker.getRegistration().then(function(reg) { reg.pushManager.subscribe({userVisibleOnly: true}) .then(function(sub) { console.log('Update Server with End Point', sub); }).catch(function(error) { console.log('Unable to subscribe user', error); }); }); }

Slide 66

Slide 66 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem or check out Propel https://github.com/GoogleChrome/propel

Slide 67

Slide 67 text

Proprietary + Confidential Handling the message

Slide 68

Slide 68 text

Handle incoming messages self.addEventListener('push', function(event) { event.waitUntil( function() { self.registration.showNotification('Title', { body: 'I\'m the message body', icon: 'images/icons.png', tag: 'tag', }); }); });

Slide 69

Slide 69 text

Handle incoming messages self.addEventListener('push', function(event) { event.waitUntil( function() { self.registration.showNotification('Title', { body: 'I\'m the message body', icon: 'images/icons.png', tag: 'tag', }); }); });

Slide 70

Slide 70 text

3. Offline That Works™ It isn't an app if it doesn't start when you tap.

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

example.com GET /app.html HTTP/1.1 HOST example.com ... HTTP/1.1 200 OK Date: Thu, 19 Feb 2015 05:21:56 GMT ...

Slide 73

Slide 73 text

example.com // sw.js onfetch = function(e) { if(e.request.url == "app.html") { e.respondWith( caches.match(e.request) ); } if(e.request.url == "content.json") { // go to the network for updates, // meanwhile, use cached content fetch(...).then(function(r) { r.asJSON().then(function(json) { e.client.postMessage(json); }); }); } }; GET /app.html HTTP/1.1 HOST example.com ... GET /content.json HTTP/1.1 HOST example.com ... GET /content.json HTTP/1.1 HOST example.com ... HTTP/1.1 200 OK Date: Thu, 19 Feb 2015... ...

Slide 74

Slide 74 text

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem or check out sw-toolbox & sw-precache https://github.com/GoogleChrome/sw-toolbox https://github.com/GoogleChrome/sw-precache

Slide 75

Slide 75 text

Confidential & Proprietary ● Reliable: Fast loading, offline and on flaky networks ● Fast: Smooth animation, scrolling and nav ● Engaging and integrated ○ On the home screen, no URL bar, icons, splash ○ Re-engaging with push notifications ● Consistent experience across browsers (still in progress, though) The Progressive Web App Experience

Slide 76

Slide 76 text

Kill Your Dinosaur!

Slide 77

Slide 77 text

Proprietary + Confidential Fin Surma @DasSurma