progressive web apps - intro & learnings

85
Image: https://yourstory.com/2017/03/progressive-web-vs-native-apps-will-mobile-experience/

Upload: johannes-weber

Post on 16-Mar-2018

110 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Progressive Web Apps - Intro & Learnings

Image: https://yourstory.com/2017/03/progressive-web-vs-native-apps-will-mobile-experience/

Page 2: Progressive Web Apps - Intro & Learnings

Johannes Weber

@jowe

Page 3: Progressive Web Apps - Intro & Learnings
Page 4: Progressive Web Apps - Intro & Learnings

Why?

What & How?

Challenges.

Page 5: Progressive Web Apps - Intro & Learnings

Why PWA?

Page 6: Progressive Web Apps - Intro & Learnings

Take Web Contentm make them offline

and usable on mobile.

Page 7: Progressive Web Apps - Intro & Learnings
Page 8: Progressive Web Apps - Intro & Learnings

Android OS Fragmentation by Device. Source: OpenSignal

Page 9: Progressive Web Apps - Intro & Learnings

http://beetfusion.com/blogs/sujit-singh/asking-key-roi-questions

Easy to Launch

Immediate Value

Offline (mostly)

Handle slow Connections

Push Notifications

Device Access

Page 10: Progressive Web Apps - Intro & Learnings

What are PWA?

Page 11: Progressive Web Apps - Intro & Learnings

What is a “Progressive Web App”?

Progressive because it works for every user

on any browser.

Responsive because it fits any form factor.

Connectivity Independent because it is

designed with the worst network in mind

App-Like as a result of the separation of

functionality from application content.

Fresh due to the service workers updating

content in the background.

Safe because it is served over HTTPS.

Discoverable since search engines are

better able to identify it as an application.

Re-engageable through features like push

notifications.

Installable on a user’s home screen for easy

access.

Linkable through a simple url.

Page 12: Progressive Web Apps - Intro & Learnings

airhorner.com

Page 13: Progressive Web Apps - Intro & Learnings

How to start with PWA?

Page 14: Progressive Web Apps - Intro & Learnings

Precondition: be on HTTPS!

Page 15: Progressive Web Apps - Intro & Learnings

Pruning the Critical Path

Tolerating Network Instability

App Like Characteristics

Page 16: Progressive Web Apps - Intro & Learnings

You Can't Optimize What You Can't Measure

Page 17: Progressive Web Apps - Intro & Learnings

Image: https://developers.google.com/web/fundamentals/performance/critical-rendering-path/measure-crp?hl=de

Page 18: Progressive Web Apps - Intro & Learnings

Image: https://medium.com/@addyosmani/progressive-web-apps-with-react-js-part-2-page-load-performance-33b932d97cf2

Page 19: Progressive Web Apps - Intro & Learnings

Request

Page 20: Progressive Web Apps - Intro & Learnings

HTML

CSS

DOM

CSSOM

JavaScriptRender

TreeLayout PaintNetwork

Critical rendering path

Page 21: Progressive Web Apps - Intro & Learnings

HTML

CSS

DOM

CSSOM

JavaScriptRender

TreeLayout PaintNetwork

Critical rendering path

Page 22: Progressive Web Apps - Intro & Learnings

DNS Lookup TCP ConnectionHTTP Request and Response

Server Response Time

Client-Side Rendering

Networkprocessing and

rendering the page

100ms 150ms 150ms 200ms 400ms

One second on a mobile device

Page 23: Progressive Web Apps - Intro & Learnings

Image Source: Aumcore.com

Offline That WorksIt isn't an app if it doesn't start when you tap.

Page 24: Progressive Web Apps - Intro & Learnings

example.com

GET /app.html HTTP/1.1HOST example.com...

HTTP/1.1 200 OKDate: Thu, 19 Feb 2015 05:21:56 GMTcache-control: must_revalidate, public, max-age=3600...

Page 25: Progressive Web Apps - Intro & Learnings

example.com

// sw.jsonfetch = 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 contentfetch(...).then(function(r) {

r.asJSON().then(function(json) {e.client.postMessage(json);

});});

}};

GET /app.html HTTP/1.1HOST example.com...

GET /content.json HTTP/1.1HOST example.com... GET /content.json HTTP/1.1

HOST example.com...

HTTP/1.1 200 OKDate: Thu, 19 Feb 2015......

Page 26: Progressive Web Apps - Intro & Learnings

// sw.jsonfetch = 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 contentfetch(...).then(function(r) {r.asJSON().then(function(json) {

e.client.postMessage(json);});

});}

};

Page 27: Progressive Web Apps - Intro & Learnings

Image: https://developers.google.com/web/fundamentals/getting-started/primers/

Worker ThreadMain Thread

Page 28: Progressive Web Apps - Intro & Learnings
Page 29: Progressive Web Apps - Intro & Learnings

Service Workers Are Network Progressive

Enhancement

A Programmable Network Proxy under your control.

Page 30: Progressive Web Apps - Intro & Learnings

w/o ServiceWorker

Page 31: Progressive Web Apps - Intro & Learnings

w/o ServiceWorker

with ServiceWorker

Page 32: Progressive Web Apps - Intro & Learnings

Application Shell

No matter what,it should at least be able to say “sorry mate, I’m offline”

Page 33: Progressive Web Apps - Intro & Learnings

Source: https://developers.google.com/web/updates/2015/11/app-shell

Page 34: Progressive Web Apps - Intro & Learnings

Image: https://sokra.github.io/slides/webpack2

Page 35: Progressive Web Apps - Intro & Learnings

Plaing Page

/w ServiceWorker

/w ServiceWorker/w ApplicationShell

Page 36: Progressive Web Apps - Intro & Learnings

DNS Lookup TCP ConnectionHTTP Request and Response

Server Response Time

Client-Side Rendering

Networkprocessing and

rendering the page

100ms 150ms 150ms 200ms 400ms

Again, that’s one second on a mobile device

Page 37: Progressive Web Apps - Intro & Learnings

Source: https://developers.google.com/web/updates/2015/11/app-shell

Cable Connection

Page 38: Progressive Web Apps - Intro & Learnings

Source: https://developers.google.com/web/updates/2015/11/app-shell

3G Connection

Page 39: Progressive Web Apps - Intro & Learnings

Resources

Guides https://goo.gl/S1yWWe, http://goo.gl/2rPg9B

Samples https://serviceworke.rs, https://goo.gl/nnPd7p

Spec slightlyoff.github.io/ServiceWorker/spec/service_worker

Page 40: Progressive Web Apps - Intro & Learnings

Pruning the Critical Path

Tolerating Network Instability

App Like Characteristics

Page 41: Progressive Web Apps - Intro & Learnings

Pruning the Critical Path

Tolerating Network Instability

App Like Characteristics

Page 42: Progressive Web Apps - Intro & Learnings

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)

<link rel="manifest"href="/manifest.json">

2. Link it to your page

Page 43: Progressive Web Apps - Intro & Learnings

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",

"orientation": "portrait",

"theme_color": "#2196F3",

"background_color": "#2196F3"

}

Page 44: Progressive Web Apps - Intro & Learnings

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",

"orientation": "portrait",

"theme_color": "#2196F3",

"background_color": "#2196F3"

}

Page 45: Progressive Web Apps - Intro & Learnings

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",

"orientation": "portrait",

"theme_color": "#2196F3",

"background_color": "#2196F3"

}

Page 46: Progressive Web Apps - Intro & Learnings

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",

"orientation": "portrait",

"theme_color": "#2196F3",

"background_color": "#2196F3"

}

Page 47: Progressive Web Apps - Intro & Learnings

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",

"orientation": "portrait",

"theme_color": "#2196F3",

"background_color": "#2196F3"

}

Page 48: Progressive Web Apps - Intro & Learnings

How to launch: browser or fullscreen

{

"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", // browser or fullscreen

"orientation": "portrait",

"theme_color": "#2196F3",

"background_color": "#2196F3"

}

Page 49: Progressive Web Apps - Intro & Learnings

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",

"orientation": "portrait",

"theme_color": "#2196F3",

"background_color": "#2196F3"

}

@media (display-mode: standalone) {

h3:after { content “ in standalone mode!”}

}

Page 50: Progressive Web Apps - Intro & Learnings

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",

"orientation": "portrait",

"theme_color": "#2196F3",

"background_color": "#2196F3"

}

Page 51: Progressive Web Apps - Intro & Learnings

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": "fullscreen",

"orientation": "landscape",

"theme_color": "#2196F3",

"background_color": "#2196F3"

}

andreasbovens.github.io/inbox-attack

Page 52: Progressive Web Apps - Intro & Learnings

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", // statistics....

"display": "standalone",

"orientation": "portrait",

"theme_color": "#2196F3",

"background_color": "#2196F3"

}

Page 53: Progressive Web Apps - Intro & Learnings

Resources

Guides https://goo.gl/UrOYcG

Samples https://goo.gl/phPpab

Spec w3c.github.io/manifest/

Page 54: Progressive Web Apps - Intro & Learnings

Push Notifications

How can we re-engage users at the right time?

Page 55: Progressive Web Apps - Intro & Learnings

Build better engagement

Page 56: Progressive Web Apps - Intro & Learnings

- Works if Browser Closed

- Needs Permission

Page 57: Progressive Web Apps - Intro & Learnings

+26%increase in average spend

per visit by members arrivingvia a push notification

+72%increase in time spent for users visiting via a push notification

+50%repeat visits within 3 months

Page 58: Progressive Web Apps - Intro & Learnings

Subscribing Users

Ask User to Subscribe

User Subscribes

Send End Point Details

Check If User Is Subscribed

Save End Point Details

Browser Server

Page 59: Progressive Web Apps - Intro & Learnings

Sending Messages

Send to End Point

Send To Browser

Received by Browser

Generate Message

Server End Point Client

Page 60: Progressive Web Apps - Intro & Learnings

Receiving Messages

SW StartsHandle

MessageShow

NotificationPush Arrives

Client

Page 61: Progressive Web Apps - Intro & Learnings

API’s

● Notification API

Handles notification display

● Service Workers API

Handles the push message when it arrives

● Push API

Enables users to (un)subscribe and receive push messages

Page 62: Progressive Web Apps - Intro & Learnings

Resources

Guides https://goo.gl/1uUCGk

Samples gauntface.github.io/simple-push-demo/

Spec w3.org/TR/push-api

Page 63: Progressive Web Apps - Intro & Learnings

Pruning the Critical Path

Tolerating Network Instability

App Like Characteristics

Page 64: Progressive Web Apps - Intro & Learnings

Challenges.

Page 65: Progressive Web Apps - Intro & Learnings

Is it worth to dig intoPWA now?

Page 66: Progressive Web Apps - Intro & Learnings
Page 67: Progressive Web Apps - Intro & Learnings

More on https://www.pwastats.com

Page 68: Progressive Web Apps - Intro & Learnings

https://jakearchibald.github.io/isserviceworkerready/index.html

Page 69: Progressive Web Apps - Intro & Learnings

Global Smartphone Sales. Source: Gartner

Page 70: Progressive Web Apps - Intro & Learnings

webpack and PWA

Page 71: Progressive Web Apps - Intro & Learnings
Page 72: Progressive Web Apps - Intro & Learnings

Use Route-Based Code Splitting

Page 73: Progressive Web Apps - Intro & Learnings
Page 74: Progressive Web Apps - Intro & Learnings
Page 75: Progressive Web Apps - Intro & Learnings

Use Smaller Images

Page 76: Progressive Web Apps - Intro & Learnings

Image: https://medium.com/@paularmstrong/twitter-lite-and-high-performance-react-progressive-web-apps-at-scale-d28a00e780a3

Page 77: Progressive Web Apps - Intro & Learnings

Image: https://medium.com/@paularmstrong/twitter-lite-and-high-performance-react-progressive-web-apps-at-scale-d28a00e780a3

Page 78: Progressive Web Apps - Intro & Learnings

Delay ServiceWorker Registration

Page 79: Progressive Web Apps - Intro & Learnings

Image: https://medium.com/@paularmstrong/twitter-lite-and-high-performance-react-progressive-web-apps-at-scale-d28a00e780a3

Page 80: Progressive Web Apps - Intro & Learnings

Image: https://medium.com/@paularmstrong/twitter-lite-and-high-performance-react-progressive-web-apps-at-scale-d28a00e780a3

Page 81: Progressive Web Apps - Intro & Learnings
Page 82: Progressive Web Apps - Intro & Learnings

THANK YOU!

Page 83: Progressive Web Apps - Intro & Learnings

https://github.com/pazguille/offline-first

https://addyosmani.com/blog/getting-started-with-progressive-web-apps/

https://docs.google.com/document/d/1y94QHbYW2Xmob6vPX2BMBvm50ojR0qD9KEwMBTHNBLg/edit#heading=h.9kr8cip

k9uk7

https://docs.google.com/document/d/1JlKBWmowi9sA5_9FCMBt9WJbTKHc9g6CYZksToCtfd4/edit#

https://serviceworke.rs/

https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web?hl=en

https://public.etherpad-mozilla.org/p/pwa-nexmo

https://ponyfoo.com/articles/serviceworker-revolution

https://ponyfoo.com/articles/progressive-networking-serviceworker

Related Links

Page 84: Progressive Web Apps - Intro & Learnings

https://github.com/GoogleChrome/sample-currency-converter

https://developers.google.com/web/ilt/pwa/introduction-to-progressive-web-app-architectures

https://habd.as/monitor-pwa-website-performance/

https://github.com/paulirish/pwmetrics

https://developers.google.com/web/showcase/

https://www.pwastats.com/

https://github.com/GoogleChrome/sw-toolbox

Related Links

Page 85: Progressive Web Apps - Intro & Learnings