50
Anatomy of a Progressive Web App January 20, 2017 Michael North Agent Conf

Anatomy of a Progressive Web App

Embed Size (px)

Citation preview

Page 1: Anatomy of a Progressive Web App

Anatomy of a Progressive Web App

January 20, 2017 Michael NorthAgent Conf

Page 2: Anatomy of a Progressive Web App

2007

Page 3: Anatomy of a Progressive Web App
Page 4: Anatomy of a Progressive Web App
Page 5: Anatomy of a Progressive Web App
Page 6: Anatomy of a Progressive Web App

A lot has changed since 2012

Page 7: Anatomy of a Progressive Web App

Benefits of Each Approach

WebNative

• Presence on home screen

• Background functionality

• Fast return startup

• Doesn’t require install

• Cross-Platform

• Very similar to desktop web experience

Page 8: Anatomy of a Progressive Web App

Vs

Page 9: Anatomy of a Progressive Web App
Page 10: Anatomy of a Progressive Web App

Progressive Web Apps

Page 11: Anatomy of a Progressive Web App

Hello!

Formerly Now

• CTO

• UI Architect @

• Lead Engineer @ Imagequix

• Training Partner @

• Staff Engineer @

• Instructor @

Page 12: Anatomy of a Progressive Web App

Major Pieces

Pruning the Critical Path

Tolerating Network Instability

App-Like Characteristics

Page 13: Anatomy of a Progressive Web App

Important Metrics

Pruning the Critical Path

🎨First Paint

👆Interactive

Time to…

📊Data

Page 14: Anatomy of a Progressive Web App

index.htmlapp.css

app.jsdata.json

API

🖥User

Asset Storage1

2

45

6

Static Hosting

3

☁CDN🎨

First Paint

👆Interactive

parse📊Data 🎨

boot

👆 📊

Client Rendered SPA

Page 15: Anatomy of a Progressive Web App

Server-Side Rendering

• ⏱ Don’t have to wait for client-side JS

• 🔗 Better for SEO & sharing links

• ⚠ Node.js and the Browser are different

• 👷 Try not to do the same work twice

• ⚡ HTML is assembled in your data center

Page 16: Anatomy of a Progressive Web App

index.htmlapp.css

app.jsdata.json

API

🖥User

Asset Storage1

2

67

8

RenderingServer

5

☁CDN🎨

First Paint

👆Interactive

parse📊Data 🎨

boot

👆📊

Server Rendered SPA

3

4

Page 17: Anatomy of a Progressive Web App

Resource Caching Strategies

• Content at a URL is never changed

• max-age=year

• index.html is the key

• Offline-friendly

• Content at a URL can change

• Cache-Control: no-cache

• Use Last-Modified or ETag

• Involves extra network requests

Immutable Content “Check w/ server”

Page 18: Anatomy of a Progressive Web App

Service Workers

• A programmable network proxy

• A JavaScript worker

• Only works over HTTPS

• Has a predictable lifecycle

XHR SW WWW

Cache

Page 19: Anatomy of a Progressive Web App

Service WorkersInstalling

Activated Error

Idle

FetchTerminated

Page 20: Anatomy of a Progressive Web App

Service Workers

I need item.pngApp

Of course! Here it is.

I have a list of important resources. I’ll fetch them all and cache them. Cache

Precache

🖼

Page 21: Anatomy of a Progressive Web App

Service Workers

App

Just got it for you!

Ok, I’ll get it Cache

Network or Cache

🖼

I need item.png

Page 22: Anatomy of a Progressive Web App

Service Workers

Took too long. Here’s a cached version🖼

App

Ok, I’ll get it Cache

Network or CacheI need item.png

Page 23: Anatomy of a Progressive Web App

Service Workers

App

Ok, I’ll get it Cache

Network or CacheI need item.png

Something went wrong. Here’s a cached version🖼

Page 24: Anatomy of a Progressive Web App

Service Workers

App

I’ll go download a new copy in case it changed

Here’s a cached version Cache

Cache and Update

🖼

I need item.png

Next time you ask, you’ll get this new version

Page 25: Anatomy of a Progressive Web App

Service Workers

App

I’ll go download a new copy in case it changed

Here’s a cached version Cache

Cache, Update and Refresh

🖼

I need item.png

Hey! I’ve got a new version. Ask me for itpostMessage

🎆

Page 26: Anatomy of a Progressive Web App

Service Workers

Page 27: Anatomy of a Progressive Web App

index.htmlapp.css

app.jsdata.json

API

🖥User

Asset Storage1

2

67

8

RenderingServer

5

☁CDN🎨

First Paint

👆Interactive parse

📊Data

🎨

boot

👆📊

Server Rendered SPA

3

4

Page 28: Anatomy of a Progressive Web App

index.html

.css.js data.json

API

🖥User

Asset Storage1

2

6

7

8

RenderingServer

5

☁CDN🎨

First Paint

👆Interactive parse

📊Data

🎨

boot

👆📊

Server Rendered PWA v1

3

4

Service

Worker

Page 29: Anatomy of a Progressive Web App

Storing Dynamic Content• Cookies - Not worker-friendly, just a string

• LocalStorage - See 👆

• What’s left???

Page 30: Anatomy of a Progressive Web App

Storing Dynamic Content• Cookies - Not worker-friendly, just a string

• LocalStorage - See 👆

IndexedDB

Page 31: Anatomy of a Progressive Web App

IndexedDB• 🔢 Versioned

• 🗃 Indexable

• ⚙ Worker-Friendly

• 📅 Durable

• 🔣 Supports values of many types

• ⚠ Not a SQL, or a relational DB

Page 32: Anatomy of a Progressive Web App

IndexedDB

!// Open (or create) the database let open = indexedDB.open('MyDatabase', 1);

!// Create and/or Migrate the Schema open.onupgradeneeded = (evt) !=> {

!// Transactions open.onsuccess = () !=> {

!!... };

!!... };

Page 33: Anatomy of a Progressive Web App

IndexedDB!// Create and/or Migrate the Schema open.onupgradeneeded = (evt) !=> {

};

let db = open.result; let store = null; switch (evt.oldVersion) { case 0: !// Upgrade from 0 !// !!... case 1: !// Upgrade from 1 !// !!... }

Page 34: Anatomy of a Progressive Web App

IndexedDB

!// Open (or create) the database let open = indexedDB.open('MyDatabase', 1);

!// Create and/or Migrate the Schema open.onupgradeneeded = (evt) !=> {

!// Transactions open.onsuccess = () !=> {

!!... };

!!... };

Page 35: Anatomy of a Progressive Web App

IndexedDB

Page 36: Anatomy of a Progressive Web App

App Shell ArchitectureShell loads instantly Dynamic content in the shell

Page 37: Anatomy of a Progressive Web App

index.html

.css.js data.json

API

🖥User

Asset Storage1

2

6

7

8

RenderingServer

5

☁CDN🎨

First Paint

👆Interactive

parse

📊Data

🎨

boot

👆📊

Server Rendered PWA v1

3

4

Service

Worker

Page 38: Anatomy of a Progressive Web App

index.html

.css.js data.json

API

🖥User

Asset Storage1

2

6

7

8

RenderingServer

5

☁CDN🎨

First Paint

👆Interactive

parse

📊Data

🎨

boot

👆📊

Server Rendered PWA v2

3

4

Service

Worker

99

shell html

First Visit

💾IndexedDB

99Records

Page 39: Anatomy of a Progressive Web App

LocalRemote

shell.html.css.js

IndexedDB

API

🖥User

Asset Storage

4

7

8

RenderingServer

3

☁CDN🎨

First Paint

👆Interactive

parse

📊Data

🎨

boot

👆 📊

Server Rendered PWA v2

Service

Worker

Return Visit

2

1

💾IndexedDB

56

data.json

Page 40: Anatomy of a Progressive Web App

Major Pieces

Pruning the Critical Path

Tolerating Network Instability

App-Like Characteristics

✅✅

Page 41: Anatomy of a Progressive Web App

App-Like Characteristics

Page 42: Anatomy of a Progressive Web App

App-Like Characteristics

<meta name="apple-mobile-web-app-capable" content="yes">Get rid of browser UI

App Icons<link sizes=“180x180" rel=“apple-touch-icon" href="icon.png">

<meta name="mobile-web-app-title" content="Mike.Works">Bookmark Name

<link href="splash.png" rel="apple-touch-startup-image">Splash Screen

Page 43: Anatomy of a Progressive Web App

App-Like Characteristics

{ "name": "Mike.Works - World Class Developer Training", "short_name": "Mike.Works", "start_url": ".", "display": "standalone", "background_color": "#fff", "theme_color": "#fff", "description": "World Class Developer Training", "orientation": "portrait-primary", "lang": "en-US", "icons": [ ] };

manifest.json

Page 44: Anatomy of a Progressive Web App

App-Like Characteristics

Page 45: Anatomy of a Progressive Web App

In The Future…• 💬 Push Notifications

• 🔁 Background Sync

• ⚛ First-Class Framework Support

• 📦 IndexedDB 2.0

• ⚡ HTTP/2 Optimizations

Page 46: Anatomy of a Progressive Web App

This is getting very complicated…

Page 47: Anatomy of a Progressive Web App

Reduce the # of decisions you must make

🤔

Page 48: Anatomy of a Progressive Web App

You will be building these things…

Page 49: Anatomy of a Progressive Web App

Get Trained.

Page 50: Anatomy of a Progressive Web App

Get Trained.

https://mike.works