Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Building Progressive Web Apps with Polymer Rob Dodson @rob_dodson +RobDodson

Slide 3

Slide 3 text

So I was on vacation.

Slide 4

Slide 4 text

So I was on vacation. In the Netherlands.

Slide 5

Slide 5 text

Progressive Web Apps!

Slide 6

Slide 6 text

?

Slide 7

Slide 7 text

Progressive Web Apps are… Responsive Connectivity independent App-like-interactions Etc… Progressive Apps: Escaping Tabs Without Losing Our Soul —

Slide 8

Slide 8 text

Progressive Web Apps are… Progressive Apps: Escaping Tabs Without Losing Our Soul — “just websites that took all the right vitamins”

Slide 9

Slide 9 text

A Progressive Web App built with Polymer

Slide 10

Slide 10 text

Responsive Load Fast Work Offline Installable Engaging our focus for today

Slide 11

Slide 11 text

Make It Responsive With app-layout Elements

Slide 12

Slide 12 text

We want to provide elements that can support any app's layout, not just for Material Design

Slide 13

Slide 13 text

Slide 14

Slide 14 text

ZUPERKÜLBLOG

Slide 15

Slide 15 text

ZUPERKÜLBLOG

Slide 16

Slide 16 text

… … add attributes for effects

Slide 17

Slide 17 text

paper-header-panel app-header-layout

Slide 18

Slide 18 text

• polymerlabs.github.io/app-layout

Slide 19

Slide 19 text

Responsive Load Fast Work Offline Installable Engaging Responsive

Slide 20

Slide 20 text

Make It Load Fast With async patterns

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Slide 23

Slide 23 text

Render blocking

Slide 24

Slide 24 text

Make sure you’re not blocking the renderer waiting on polyfills or elements

Slide 25

Slide 25 text

Slide 26

Slide 26 text

async unblocks the renderer

Slide 27

Slide 27 text

Should you load the polyfills in every browser?

Slide 28

Slide 28 text

Should you load the polyfills in every browser? No.

Slide 29

Slide 29 text

Slide 30

Slide 30 text

Slide 31

Slide 31 text

Slide 32

Slide 32 text

var webComponentsSupported = ('registerElement' in document && 'import' in document.createElement('link') && 'content' in document.createElement('template')); do we need polyfills?

Slide 33

Slide 33 text

var webComponentsSupported = ('registerElement' in document && 'import' in document.createElement('link') && 'content' in document.createElement('template')); if (!webComponentsSupported) { var script = document.createElement('script'); script.async = true; script.src = 'webcomponents-lite.min.js'; script.onload = finishLazyLoading; document.head.appendChild(script); } else { finishLazyLoading(); } lazy load ‘em

Slide 34

Slide 34 text

Slide 35

Slide 35 text

Slide 36

Slide 36 text

Slide 37

Slide 37 text

Slide 38

Slide 38 text

Use the :unresolved pseudo-class to style unupgraded elements browser must support Custom Elements * *

Slide 39

Slide 39 text

app-header-layout:unresolved { height: 192px; background: #FFF; } … style unupgraded elements

Slide 40

Slide 40 text

app-header-layout[unresolved] { height: 192px; background: #FFF; } … manage attributes

Slide 41

Slide 41 text

Create a skeleton that mimics the look of your app shell.

Slide 42

Slide 42 text

#skeleton .header { height: 192px; background: #FFF; }
fast paint skeleton while element upgrades

Slide 43

Slide 43 text

original version async + skeleton

Slide 44

Slide 44 text

Responsive Load Fast Work Offline Installable Engaging Responsive Load Fast

Slide 45

Slide 45 text

Make It Work Offline With platinum-sw Elements

Slide 46

Slide 46 text

A service worker is a script that is run by your browser in the background, separate from a web page” Introduction to Service Worker — “

Slide 47

Slide 47 text

// updated service worker is activated. var CACHE_VERSION = 1; var CURRENT_CACHES = { 'read-through': 'read-through-cache-v' + CACHE_VERSION }; self.addEventListener('activate', function(event) { // Delete all caches that aren't named in CURRENT_CACHES. // While there is only one cache in this example, the same logic will handle the case where // there are multiple versioned caches. var expectedCacheNames = Object.keys(CURRENT_CACHES).map(function(key) { return CURRENT_CACHES[key]; }); event.waitUntil( caches.keys().then(function(cacheNames) { return Promise.all( cacheNames.map(function(cacheName) { if (expectedCacheNames.indexOf(cacheName) == -1) { // If this cache name isn't present in the array of "expected" cache names, then delete it. console.log('Deleting out of date cache:', cacheName); return caches.delete(cacheName);

Slide 48

Slide 48 text

Libraries like sw-toolbox and sw-precache abstract these low level complexities

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Elements to turn your web page into a true web app, with push, offline, bluetooth and more.

Slide 51

Slide 51 text

Elements to turn your web page into a true web app, with push, offline, bluetooth and more. progressive

Slide 52

Slide 52 text

Slide 53

Slide 53 text

Slide 54

Slide 54 text

Take advantage of sw-toolbox

Slide 55

Slide 55 text

Caching Strategies fastest: race the cache and network networkFirst: try the network, then the cache networkOnly: try the network, else fail

Slide 56

Slide 56 text

Configure your caching strategy

Slide 57

Slide 57 text

Prefetch everything for your app shell

Slide 58

Slide 58 text

Prefetch an array of file paths

Slide 59

Slide 59 text

…Or a json file

Slide 60

Slide 60 text

{ "cacheId": "zuperkulblog", "disabled": false, "precache": [ "data\/art.json", "data\/film.json", "scripts\/app.js", ".\/", "bower_components\/webcomponentsjs\/webcomponents-lite.min.js" ], "precacheFingerprint": "847c082ce8e3eb8c54054a7cdc76544e" } Example cache-config.json

Slide 61

Slide 61 text

{ "cacheId": "zuperkulblog", "disabled": false, "precache": [ "data\/art.json", "data\/film.json", "scripts\/app.js", ".\/", "bower_components\/webcomponentsjs\/webcomponents-lite.min.js" ], "precacheFingerprint": "847c082ce8e3eb8c54054a7cdc76544e" } Example cache-config.json Change this to tell SW to precache files again

Slide 62

Slide 62 text

Check out the cache-config gulp task in the Polymer Starter Kit project for an example of generating at build time Polymer Starter Kit, gulpfile.js —

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

Responsive Load Fast Work Offline Installable Engaging Responsive Load Fast Work Offline

Slide 65

Slide 65 text

Make It Installable With a Web App install banner

Slide 66

Slide 66 text

Your App Must… ✓ Have a Web App Manifest ✓ Have a registered Service Worker ✓ Be served over HTTPS ✓ Be visited twice, with at least 5 minutes between visits* Increasing engagement with Web App install banners —

Slide 67

Slide 67 text

Your App Must… ✓ Have a Web App Manifest ✓ Have a registered Service Worker ✓ Be served over HTTPS ✓ Be visited twice, with at least 5 minutes between visits* Increasing engagement with Web App install banners — may change

Slide 68

Slide 68 text

{ "name": "Zuperkülblog", "short_name": "Zuperkülblog", "icons": [{ "src": "images/touch/icon-128x128.png", "sizes": "128x128", "type": "image/png" }, … { "src": "images/touch/chrome-splashscreen-icon-384x384.png", "sizes": "384x384", "type": "image/png" }], "start_url": "/?homescreen=1", "background_color": "#3E4EB8", "display": "standalone", "theme_color": "#FFFFFF" }

Slide 69

Slide 69 text

{ "name": "Zuperkülblog", "short_name": "Zuperkülblog", "icons": [{ "src": "images/touch/icon-128x128.png", "sizes": "128x128", "type": "image/png" }, … { "src": "images/touch/chrome-splashscreen-icon-384x384.png", "sizes": "384x384", "type": "image/png" }], "start_url": "/?homescreen=1", "background_color": "#3E4EB8", "display": "standalone", "theme_color": "#FFFFFF" }

Slide 70

Slide 70 text

Slide 71

Slide 71 text

Be sure to also include fallback meta tags.

Slide 72

Slide 72 text

Slide 73

Slide 73 text

HMmmm…

Slide 74

Slide 74 text

“But, I’m all lazy… ’n stuff…”

Slide 75

Slide 75 text

Polymer Starter Kit gives you a working manifest, meta tags, and device icons. Polymer Starter Kit —

Slide 76

Slide 76 text

So… Is This Thing Working? Debugging your banner

Slide 77

Slide 77 text

chrome://flags/#bypass-app-banner-engagement-checks Enable the bypass flag to test your banner

Slide 78

Slide 78 text

Watch Out For This Gotcha Revenge of the offline dino

Slide 79

Slide 79 text

{ "name": "Zuperkülblog", "short_name": "Zuperkülblog", "icons": [{ "src": "images/touch/icon-128x128.png", "sizes": "128x128", "type": "image/png" }, … { "src": "images/touch/chrome-splashscreen-icon-384x384.png", "sizes": "384x384", "type": "image/png" }], "start_url": "/?homescreen=1", "background_color": "#3E4EB8", "display": "standalone", "theme_color": "#FFFFFF" } oh hai! :)

Slide 80

Slide 80 text

By default, the request URL must exactly match the URL used to store the cached response, including any query parameters in the search portion of the URL.” Service Workers in Production — “

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

Responsive Load Fast Work Offline Installable Engaging Responsive Load Fast Work Offline Installable

Slide 83

Slide 83 text

Make It Engaging With Push Notifications

Slide 84

Slide 84 text

Don’t spam.

Slide 85

Slide 85 text

Don’t spam. Seriously.

Slide 86

Slide 86 text

Let the user decide when they want to opt-in to push messaging.

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

Slide 89

Slide 89 text

Slide 90

Slide 90 text

Slide 91

Slide 91 text

// On your server… app.get('/notification-data.json', function (req, res) { res.json({ 'title': 'Zuperkülblog just posted…', 'message': 'Demystifying Density by Sebastien Gabriel', 'url': ‘https://zuperkulblog.appspot.com/…’, 'icon': '/images/article/demystifying-192x192.png', 'tag': 'zuperkulblog-push-notification' }); });

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

github.com/notwaldorf/caturday-post

Slide 94

Slide 94 text

The food in my bowl Is old, and more to the point Contains no tuna.

Slide 95

Slide 95 text

Responsive Load Fast Work Offline Installable Engaging Responsive Load Fast Work Offline Installable Engaging

Slide 96

Slide 96 text

In Closing… (yes it’s finally over)

Slide 97

Slide 97 text

you

Slide 98

Slide 98 text

you the web

Slide 99

Slide 99 text

Things are getting kind of awesome

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

itshackademic.com

Slide 102

Slide 102 text

credits Images by Paul F., Jinhwan Kim, Wolff, Pirog Tetyana, Dani Rolli, Julien Deveaux, Matt Brooks, Pablo Rozenberg, Ribbla Team, Jennifer Goodman, Dan Lowenstein, Blaise Sewell, Arturo Alejandro Romo Escartin Project thanks! @rob_dodson +RobDodson github.com/polymerlabs/zuperkulblog-progressive source