Explores progressive web apps, what advantages they have versus native apps, how to build, and test them, and some of the challenges we still have ahead.
Slides from talk at London Web Standards, Nov 2016
Andy DaviesIndependent Web Performance Consultant at Asteno
29. So what might we need to build it?
https://www.flickr.com/photos/aigle_dore/7912377858
30. We can already add pages to our home screen
Supported by most major mobile
operating systems and browsers
(Bookmarks page rather than site)
31. Can specify the icon etc. via meta tags
<link rel="apple-touch-icon" href="icons/logo/ncc-logo-120x120-ios.png">
<link rel="apple-touch-icon-precomposed" href="icons/logo/ncc-logo-120x120-ios.png">
<link rel="apple-touch-startup-image" href="/images/startup.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
(Minimal iOS set, ideally need more icon and splash screen sizes
and other mobile browsers prefer different meta data)
37. And can even offer an install prompt
(Browsers use several heuristics before deciding to prompt)
38. Can listen for install event and track in analytics
window.addEventListener('beforeinstallprompt', function(e) {
e.userChoice.then(function(choiceResult) {
console.log(choiceResult.outcome);
if (choiceResult.outcome == 'dismissed') {
// Track not installed
} else {
// Track installation
}
});
});
(Chrome supports this but it’s not in AppManifest standard)
39. Can listen for install event and track in analytics
window.addEventListener('appinstalled', function(e) {
// Track installation
});
(AppManifest standard proposes this)
40. But how do we cope with a poor (or no) network?
https://www.flickr.com/photos/odaeus/3942500793
44. Service Worker is an in-browser network proxy
that can intercept requests and responses
45. <script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('serviceworker.js', {
scope: '/'
}).then(function(registration) {
// Anything else you want to do with registration
// e.g. subscribe to push messages
}).catch(function(err) {
console.log('Can't register service worker: ', err);
});
}
</script>
Register a Service Worker
46. Option to install via Link may be coming
<link rel="serviceworker" scope="/" href=“/serviceworker.js">
or
Link </serviceworker.js>; rel=serviceworker scope=/
(Origin trial in Chrome, under consideration in Firefox)
51. Going offline - retrieving from cache on fetch
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
Try the cache first and go to the
network if there’s no match
53. Caching as a fallback for network
• Make a request
• Succeeds - cache response and return it
• Fails - check cache and return cached response
• Network request fails and not in cache ¯_( )_/¯
(OK so you probably want to manage the users experience in the last case)
54. Caching patterns depend on use case, some very helpful resources
Mozilla https://serviceworke.rs/
Jake Archibald https://jakearchibald.com/2014/offline-cookbook/
ServiceWork Toolbox https://github.com/GoogleChrome/sw-toolbox
62. Powerful APIs (inc Service Worker) require HTTPS
https://www.flickr.com/photos/zebble/6080622
63. “The future is here, it’s just unevenly distributed”
✓ ✓ ✓ WiP ?✓
64. We’re getting better access to native features
• Camera
• Notifications
• Location
• Geofencing
• Alarms
• Vibration
• Sharing
• Battery
• and more…
(On some platforms)
72. You can deploy them today
• 3x more time spent on site
• 40% higher re-engagement rate
• 70% greater conversion rate for
those arriving via Homescreen
• 3x lower data usage
75. These apps aren’t packaged and deployed through stores,
they’re just websites that took all the right vitamins
https://infrequently.org/2015/06/progressive-apps-escaping-tabs-without-losing-our-soul/
Alex Russell, Google
76. I still have questions…
• What might not be suitable as a progressive web app?
• Can we build PWAs that are as fast and frictionless as native?
• How can we sell our apps, will we need app stores?
• How do we avoid an uncanny UI valley?
• What happens to storage when every site is a PWA?
77. “Every step on the path to a PWA makes sense on it’s own”
Jason Grigsby