Progressive web applications

T
Progressive Web
Applications
Overview
● Why progressive?
● Service Workers
● Cache API
● IndexedDB
● Manifest
● Current Browser Support
● Development with Lighthouse
● Build Tools & Plugins
● The Future
● Don’t make network connectivity, browser or device choice a limiting factor
● Boost web app performance even for good connectivity
● Enable engagement for offline users
● Create a native-like experience
● Four components: service workers, cache API, IndexedDB, manifest file
Why Progressive?
● Progressive web apps bigger topic than offline support
● AppCache difficult to work with
● Alternative with service workers and cache API
● Service workers are just code
● Simple, repeatable patterns
Service Workers: the Why
Service Workers: the What
● Run in their own worker context (no DOM access)
● Use postMessage, onMessage for child/parent communication
● Fully asynchronous
● Have access to cache API and fetch API
● Basic idea: service workers act as a proxy server
● HTTPS only
Service Workers: the How
● Lots of ways to do this…
● Progressive Enhancement: Register service worker
● Declare network resources to cache
● Subsequent page request fetch cached resources
● Can additionally choose to fetch updated resources from network
Service Workers to the Rescue: Service worker lifecycle
Waiting
Terminated
Fetch /
Message
Error
Install
Activate
Idle
No Service
Worker
Demo
More about Cache API
● Request/Response storage
● Origin can have multiple cache objects
● Should periodically delete unused caches to be safe
● Cache polyfill (https://github.com/coonsta/cache-polyfill)
IndexedDB
● Allow storage of larger, more structured datasets
● Supports queries, cursors etc.
● Transactional, Object-Orientated database
● Built with async in mind, indexeddb-promised (for Chrome only)
Manifest
● Specify appearance of web app
● More native-like experience
● Example
● Include with link tag
<link rel="manifest" href="/manifest.json">
Manifest: Example
Current Browser Support
● Basically just Chrome, Firefox, and Opera for the time being
● Is Service Worker Ready?
● Also polyfills for different APIs
● Chrome has good support for development
○ DevTools: Toggle force upload in sources tab
○ DevTools: Clear cache/unregister service workers with “clear storage”
○ Check running service workers: chrome://inspect/#service-workers
○ Check all registered instances: chrome://serviceworker-internals/
Development with Lighthouse
● Service worker helper module
● And for grunt/gulp
Build Tools & Plugins
● Identity streams
● Navigation preload
● Foreign fetch
● Background Fetch
● Future App Model: Advanced Service Worker (Video)
The Future
Examples
● Production
○ Flipkart
○ Washington Post
○ Ali Express
● Offline ToDo
● Other examples
○ Trained to Thrill
○ Offline News
Get in Touch: @tpgmartin
● Blog
● Twitter
● GitHub
● Progressive Web Apps
○ Addy Osmani
○ Google Developers
○ pazguille/offline-first
○ Udacity: Offline Web Applications
● Service Workers
○ Introduction to Service Workers
References
● Application Cache
● Cache API
● IndexedDB
○ Using IndexedDB
● Browser Support
References
1 of 20

Recommended

Gutenberg: You Can't Teach an Old Dev New Tricks - WordCamp Chicago 2018 by
Gutenberg: You Can't Teach an Old Dev New Tricks - WordCamp Chicago 2018Gutenberg: You Can't Teach an Old Dev New Tricks - WordCamp Chicago 2018
Gutenberg: You Can't Teach an Old Dev New Tricks - WordCamp Chicago 2018Mike Hale
322 views41 slides
Jayway Web Tech Radar 2015 by
Jayway Web Tech Radar 2015Jayway Web Tech Radar 2015
Jayway Web Tech Radar 2015Gustaf Nilsson Kotte
965 views36 slides
Host, deploy & scale Blazor Server Apps by
Host, deploy & scale Blazor Server AppsHost, deploy & scale Blazor Server Apps
Host, deploy & scale Blazor Server AppsJose Javier Columbie
103 views19 slides
Website cloning using backtrack 5 by
Website cloning using backtrack 5Website cloning using backtrack 5
Website cloning using backtrack 5Tamajit Chakraborty
2.7K views11 slides
Simpler Web Architectures Now! (At The Frontend 2016) by
Simpler Web Architectures Now! (At The Frontend 2016)Simpler Web Architectures Now! (At The Frontend 2016)
Simpler Web Architectures Now! (At The Frontend 2016)Gustaf Nilsson Kotte
847 views23 slides
ITT Flisol 2013 by
ITT Flisol 2013ITT Flisol 2013
ITT Flisol 2013Domingo Suarez Torres
881 views24 slides

More Related Content

What's hot

WebAssembly by
WebAssemblyWebAssembly
WebAssemblyJawahar
60 views47 slides
Enterprise Griffon by
Enterprise GriffonEnterprise Griffon
Enterprise GriffonJames Williams
634 views29 slides
Future development stack ~ MeteorJS by
Future development stack ~ MeteorJSFuture development stack ~ MeteorJS
Future development stack ~ MeteorJSVictor Stan
1.1K views12 slides
Polymer & PWA: Understanding the “why” by
Polymer & PWA: Understanding the “why”Polymer & PWA: Understanding the “why”
Polymer & PWA: Understanding the “why”Ashrith Kulai
136 views45 slides
Frost - W3C Mobile Ajax Workshop 2007 by
Frost - W3C Mobile Ajax Workshop 2007Frost - W3C Mobile Ajax Workshop 2007
Frost - W3C Mobile Ajax Workshop 2007Rocco Georgi
372 views7 slides
Performance anti patterns in ajax applications by
Performance anti patterns in ajax applicationsPerformance anti patterns in ajax applications
Performance anti patterns in ajax applicationsSergeyChernyshev
1.2K views18 slides

What's hot(20)

WebAssembly by Jawahar
WebAssemblyWebAssembly
WebAssembly
Jawahar 60 views
Future development stack ~ MeteorJS by Victor Stan
Future development stack ~ MeteorJSFuture development stack ~ MeteorJS
Future development stack ~ MeteorJS
Victor Stan1.1K views
Polymer & PWA: Understanding the “why” by Ashrith Kulai
Polymer & PWA: Understanding the “why”Polymer & PWA: Understanding the “why”
Polymer & PWA: Understanding the “why”
Ashrith Kulai136 views
Frost - W3C Mobile Ajax Workshop 2007 by Rocco Georgi
Frost - W3C Mobile Ajax Workshop 2007Frost - W3C Mobile Ajax Workshop 2007
Frost - W3C Mobile Ajax Workshop 2007
Rocco Georgi372 views
Performance anti patterns in ajax applications by SergeyChernyshev
Performance anti patterns in ajax applicationsPerformance anti patterns in ajax applications
Performance anti patterns in ajax applications
SergeyChernyshev1.2K views
TSSJS2010 Presenatation on: Performance Anti Patterns In Ajax Applications by guestc75cdc
TSSJS2010 Presenatation on: Performance Anti Patterns In Ajax ApplicationsTSSJS2010 Presenatation on: Performance Anti Patterns In Ajax Applications
TSSJS2010 Presenatation on: Performance Anti Patterns In Ajax Applications
guestc75cdc777 views
Professional JavaScript Error-Logging by Kai Donato
Professional JavaScript Error-LoggingProfessional JavaScript Error-Logging
Professional JavaScript Error-Logging
Kai Donato957 views
RESTful with Drupal - in-s and out-s by Kalin Chernev
RESTful with Drupal - in-s and out-sRESTful with Drupal - in-s and out-s
RESTful with Drupal - in-s and out-s
Kalin Chernev816 views
Full stack JavaScript - the folly of choice by FDConf
Full stack JavaScript - the folly of choiceFull stack JavaScript - the folly of choice
Full stack JavaScript - the folly of choice
FDConf4.1K views
Free Online SharePoint Framework Webinar by Manoj Mittal
Free Online SharePoint Framework WebinarFree Online SharePoint Framework Webinar
Free Online SharePoint Framework Webinar
Manoj Mittal133 views
The Importance Things of Full Stack Development by Mike Taylor
The Importance Things of Full Stack DevelopmentThe Importance Things of Full Stack Development
The Importance Things of Full Stack Development
Mike Taylor991 views
Front-end tools in java webapps by benfante
Front-end tools in java webappsFront-end tools in java webapps
Front-end tools in java webapps
benfante634 views
Headless Drupal with AngularJS by valuebound
Headless Drupal with AngularJSHeadless Drupal with AngularJS
Headless Drupal with AngularJS
valuebound4.5K views

Similar to Progressive web applications

You Can Be an Open Source Library by
You Can Be an Open Source LibraryYou Can Be an Open Source Library
You Can Be an Open Source LibraryMyka Kennedy Stephens
145 views25 slides
JIO and WebViewers: interoperability for Javascript and Web Applications by
JIO and WebViewers: interoperability  for Javascript and Web ApplicationsJIO and WebViewers: interoperability  for Javascript and Web Applications
JIO and WebViewers: interoperability for Javascript and Web ApplicationsXWiki
1.4K views29 slides
Refactoring to a Single Page Application by
Refactoring to a Single Page ApplicationRefactoring to a Single Page Application
Refactoring to a Single Page ApplicationCodemotion
815 views39 slides
Refactoring to a SPA by
Refactoring to a SPARefactoring to a SPA
Refactoring to a SPAMarcello Teodori
534 views39 slides
Web Performance Optimization by
Web Performance OptimizationWeb Performance Optimization
Web Performance OptimizationLivares Technologies Pvt Ltd
36 views33 slides
About order form improvements by
About order form improvementsAbout order form improvements
About order form improvementsGengo
5K views14 slides

Similar to Progressive web applications(20)

JIO and WebViewers: interoperability for Javascript and Web Applications by XWiki
JIO and WebViewers: interoperability  for Javascript and Web ApplicationsJIO and WebViewers: interoperability  for Javascript and Web Applications
JIO and WebViewers: interoperability for Javascript and Web Applications
XWiki1.4K views
Refactoring to a Single Page Application by Codemotion
Refactoring to a Single Page ApplicationRefactoring to a Single Page Application
Refactoring to a Single Page Application
Codemotion815 views
About order form improvements by Gengo
About order form improvementsAbout order form improvements
About order form improvements
Gengo5K views
Introduction to Gengo's New Order Form tech by Gengo
Introduction to Gengo's New Order Form techIntroduction to Gengo's New Order Form tech
Introduction to Gengo's New Order Form tech
Gengo3.5K views
#RADC4L16: An API-First Archives Approach at NPR by Camille Salas
#RADC4L16: An API-First Archives Approach at NPR#RADC4L16: An API-First Archives Approach at NPR
#RADC4L16: An API-First Archives Approach at NPR
Camille Salas1.2K views
Web performance optimization - MercadoLibre by Pablo Moretti
Web performance optimization - MercadoLibreWeb performance optimization - MercadoLibre
Web performance optimization - MercadoLibre
Pablo Moretti2.5K views
Creating a custom API for a headless Drupal by Exove
Creating a custom API for a headless DrupalCreating a custom API for a headless Drupal
Creating a custom API for a headless Drupal
Exove1.8K views
Mean Stack - An Overview by Naveen Pete
Mean Stack - An OverviewMean Stack - An Overview
Mean Stack - An Overview
Naveen Pete1K views
AD113 Speed Up Your Applications w/ Nginx and PageSpeed by edm00se
AD113  Speed Up Your Applications w/ Nginx and PageSpeedAD113  Speed Up Your Applications w/ Nginx and PageSpeed
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
edm00se1K views
Node.js Web Apps @ ebay scale by Dmytro Semenov
Node.js Web Apps @ ebay scaleNode.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scale
Dmytro Semenov1.8K views
Web App Prototypes with Google App Engine by Vlad Filippov
Web App Prototypes with Google App EngineWeb App Prototypes with Google App Engine
Web App Prototypes with Google App Engine
Vlad Filippov984 views
Web performance mercadolibre - ECI 2013 by Santiago Aimetta
Web performance   mercadolibre - ECI 2013Web performance   mercadolibre - ECI 2013
Web performance mercadolibre - ECI 2013
Santiago Aimetta1.2K views
Design Summit - Technology Vision - Oleg Barenboim and Jason Frey by ManageIQ
Design Summit - Technology Vision - Oleg Barenboim and Jason FreyDesign Summit - Technology Vision - Oleg Barenboim and Jason Frey
Design Summit - Technology Vision - Oleg Barenboim and Jason Frey
ManageIQ1.3K views

Recently uploaded

Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesShapeBlue
210 views15 slides
NTGapps NTG LowCode Platform by
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform Mustafa Kuğu
365 views30 slides
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlueShapeBlue
103 views23 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
50 views73 slides
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOsPriyanka Aash
153 views59 slides
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool by
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPoolShapeBlue
84 views10 slides

Recently uploaded(20)

Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue210 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu365 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue103 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash153 views
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool by ShapeBlue
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool
ShapeBlue84 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE69 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue158 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue138 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays53 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc160 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue93 views
The Role of Patterns in the Era of Large Language Models by Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li80 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue117 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue120 views
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... by ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue144 views
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue176 views

Progressive web applications

  • 2. Overview ● Why progressive? ● Service Workers ● Cache API ● IndexedDB ● Manifest ● Current Browser Support ● Development with Lighthouse ● Build Tools & Plugins ● The Future
  • 3. ● Don’t make network connectivity, browser or device choice a limiting factor ● Boost web app performance even for good connectivity ● Enable engagement for offline users ● Create a native-like experience ● Four components: service workers, cache API, IndexedDB, manifest file Why Progressive?
  • 4. ● Progressive web apps bigger topic than offline support ● AppCache difficult to work with ● Alternative with service workers and cache API ● Service workers are just code ● Simple, repeatable patterns Service Workers: the Why
  • 5. Service Workers: the What ● Run in their own worker context (no DOM access) ● Use postMessage, onMessage for child/parent communication ● Fully asynchronous ● Have access to cache API and fetch API ● Basic idea: service workers act as a proxy server ● HTTPS only
  • 6. Service Workers: the How ● Lots of ways to do this… ● Progressive Enhancement: Register service worker ● Declare network resources to cache ● Subsequent page request fetch cached resources ● Can additionally choose to fetch updated resources from network
  • 7. Service Workers to the Rescue: Service worker lifecycle Waiting Terminated Fetch / Message Error Install Activate Idle No Service Worker
  • 9. More about Cache API ● Request/Response storage ● Origin can have multiple cache objects ● Should periodically delete unused caches to be safe ● Cache polyfill (https://github.com/coonsta/cache-polyfill)
  • 10. IndexedDB ● Allow storage of larger, more structured datasets ● Supports queries, cursors etc. ● Transactional, Object-Orientated database ● Built with async in mind, indexeddb-promised (for Chrome only)
  • 11. Manifest ● Specify appearance of web app ● More native-like experience ● Example ● Include with link tag <link rel="manifest" href="/manifest.json">
  • 13. Current Browser Support ● Basically just Chrome, Firefox, and Opera for the time being ● Is Service Worker Ready? ● Also polyfills for different APIs ● Chrome has good support for development ○ DevTools: Toggle force upload in sources tab ○ DevTools: Clear cache/unregister service workers with “clear storage” ○ Check running service workers: chrome://inspect/#service-workers ○ Check all registered instances: chrome://serviceworker-internals/
  • 15. ● Service worker helper module ● And for grunt/gulp Build Tools & Plugins
  • 16. ● Identity streams ● Navigation preload ● Foreign fetch ● Background Fetch ● Future App Model: Advanced Service Worker (Video) The Future
  • 17. Examples ● Production ○ Flipkart ○ Washington Post ○ Ali Express ● Offline ToDo ● Other examples ○ Trained to Thrill ○ Offline News
  • 18. Get in Touch: @tpgmartin ● Blog ● Twitter ● GitHub
  • 19. ● Progressive Web Apps ○ Addy Osmani ○ Google Developers ○ pazguille/offline-first ○ Udacity: Offline Web Applications ● Service Workers ○ Introduction to Service Workers References
  • 20. ● Application Cache ● Cache API ● IndexedDB ○ Using IndexedDB ● Browser Support References

Editor's Notes

  1. This presentation will provide a high level introduction and overview of the technologies behind progressive web apps: service workers, cache API, IndexedDB, and the manifest file. I’ve decided to structure the presentation in this for at least two reasons I can think of. Firstly, the technologies behind progressive web apps, while not exactly brand new, are not equally implemented in all browsers as yet if at all. Secondly, as a self contained subject progressive web apps is fairly brief, meaning either you know nothing about them at all or pretty much everything there is to know. If I haven’t lost you at this point, good! Let’s continue.
  2. This presentation will provide a high level introduction and overview of the technologies behind progressive web apps: service workers, cache API, IndexedDB, and the manifest file. I’ve decided to structure the presentation in this for at least two reasons I can think of. Firstly, the technologies behind progressive web apps, while not exactly brand new, are not equally implemented in all browsers as yet if at all. Secondly, as a self contained subject progressive web apps is fairly brief, meaning either you know nothing about them at all or pretty much everything there is to know. If I haven’t lost you at this point, good! Let’s continue.
  3. With all that said, why do we care about progressive web apps? Really, what we want is to ensure that neither network connectivity, browser or device choice is a limiting factor for using our web application. In fact, we can go further than this and enhance the app performance for the whole range of network connectivity. At the one end, with ideal network connectivity, we can ensure that the page loads as quickly as possible by fetching locally cached assets instead of fetching them across the network. At the other end, with poor or even no connectivity, we can serve up some experience where this would not have been possible. More broadly, progressive web apps unlock multiple capabilities such as push notifications and web app display customisation that compete directly with a native app. We can make the move to much more lightweight web app alternatives that much more compelling. I should also flag up some conflation between progressive web apps and offline-first initiatives. Although progressive web apps enable offline interaction, offline should never be the end goal - we really just care about reliability over flaky network connections. Offline is just a nice add-on, but that won’t stop be using the term! Also should make clear, this is only considering the current Chrome support
  4. AppCache is just a configuration manifest - problems we have in development simply require us to read documentation. Other problems: forcing updates, reads from cache even if offline etc. Service workers are again case of code over configuration: can debug, test etc. We have complete control over the experience Repeatable patterns: exists plugins to save us time of writing from scratch every time Service workers and cache can be used independently, but together can be effective replacement for AppCache
  5. Moving on to progressive web apps as there are now. The main workhouse are service workers “Workers” as in run in own thread in browser. A service worker is run in a worker context: it therefore has no DOM access, and runs on a different thread to the main JavaScript that powers your app, so it is not blocking. It is designed to be fully async; as a consequence, APIs such as synchronous XHR and localStorage can't be used inside a service worker. Both main program and service worker pattern work in event dispatch / event listening Perhaps no surprise that service workers are fully asynchronous. , APIs such as synchronous XHR and localStorage can't be used inside a service worker. Access to multiple API such as cache API and fetch API. Will return to cache API later, but for completeness just discuss fetch a bit more here. fetch API is a new alternative to XHR API with full promise support. Basic idea: service worker acts a programmable proxy server Because of this, service workers must be served over HTTPS only to prevent man in the middle attacks. Can still develop on localhost - considered secure origin Lifecycle independent of the page: assets, page, and service worker have separate lifetimes. In fact the service worker has a maximum lifespan of 24hours. We will go into this a bit more soon, but to elaborate, after 24 hours, the browser will look to replace the existing service worker once all
  6. The specific implementation of a progressive web depends very much on the kind of web app you are developing, and the kind of progressive experience you want to enable. For this presentation and the demo, I will consider the case where we have a hard dependency on our assets - we need them for the page to load as expected. If you are interested in other patterns, this link is to an article by Jake Archibald talking about different strategies for both caching and serving assets. In our case, we are going to register the service worker as a progressive enhancement in the main app script. Then in the service worker script, we will declare the resources to cache and well, cache them. On a subsequent page reload, the service worker will step in and serve up the cached assets. Additionally, we can make the further step in our fetch event, we can request missing assets from the network if needs be.
  7. Before looking at some code, let’s look at the service worker lifecycle in a bit more detail A service worker has a lifecycle that is completely separate from your web page. To install a service worker for your site, you need to register it, which you do in your page's JavaScript. Registering a service worker will cause the browser to start the service worker install step in the background. We use eventhandlers to bind the install, activate and fetch events During the install step, you'll want to cache some static assets. If all the files are cached successfully, then the service worker becomes installed. If any of the files fail to download and cache, then the install step will fail and the service worker won't activate (i.e. won't be installed). If that happens, don't worry, it'll try again next time. But that means if it does install, you know you've got those static assets in the cache. At the activation step we handle management of old caches, which we'll cover during the service worker update section. After the activation step, the service worker will control all pages that fall under its scope, though the page that registered the service worker for the first time won't be controlled until it's loaded again. Once a service worker is in control, it will be in one of two states: either the service worker will be terminated to save memory, or it will handle fetch and message events that occur when a network request or message is made from your page. Only ever one service worker in control of a page at one time, if there is already an active service worker for a given page, a new service worker is queued in the waiting state. Once all instances of the current web app are closed, the old service worker is prepped for deletion and the new worker is activated. A new service worker is required usually due to some update to the service worker script. We can force a service worker update through basic cache invalidation e.g. changing the name of our assets cache. Downloaded at least every 24 hours
  8. From project code: Implementation in sw.js sw.js can only have scope of files either in the immediate directory it is placed in or subdirectories. For this reason it is typical to place service at project root. It may be preferable in development to place the service worker, then at build time move it to project root Discuss `filesToCache` array Discuss event listeners Register in js/app.js Progressive enhancement Can specify scope - this limits files service workers can access I’m now going to demonstrate this behaviour in the browser Service worker installation event Refresh cache storage to show update cache Service worker fetch Service worker response Showw offline Application > Cache > Cache Storage > static cache name (specified in sw.js) Application > Service workers > toggle “Update on reload” Installing a new service worker - will automatically if service worker changed, e.g. versioning assets We are using localstorage to store todos, and cache API for static assets
  9. Browsers have hard limit as to how much disk space is made available to a given origin - should ensure that caches are frequently purged A single origin can have multiple cache objects, collected under the CacheStorage API As of Chrome 46, the Cache API will only store requests from secure origins, meaning those served over HTTPS. More flexible than AppCache
  10. Service workers have no persistent state - require indexedDB to support multiple service workers LocalStorage does not support query language Transactions good for dealing with problems that may arise from multiple instances across multiple tabs. Transactions are atomic. Transaction scope is defined when it is initialised and fixed for the lifetime of the transaction. This to prevent possible overlap with multiple writes to the same object store. This is designed to prevent race conditions.
  11. Include link tag in main HTML file It is a best practice to place the manifest link on all your site’s pages, so it will be retrieved by Chrome right when the user first visits, no matter what page they land on. Demo with GIF
  12. DevTools: Toggle force upload in sources tab - force new service worker install event on cmd-r/ctrl-r Use serviceworker-internals to debug failing installations
  13. Available as CLI and chrome plugin - audits page to show presence of service worker, 200 status when offline, and other useful metrics
  14. Service workers have been around since 2013 All these are still in progress Achieve good performance even with full page reloads (server reloads) without javascript Stream are a big deal in front end web development nowaday. Identity streams: stream resources in the background without requiring javascript Navigation preload: quicker network response time, at same time as service worker boot up Service-worker-navigation-preload header Foreign fetch: dedupe third party requires via service worker Background fetch: solve issues caused by background sync, higher visibility