1 of 23

Introduction to PWA Architectures

Progressive Web Apps

1

1

1

Progressive Web Apps

Progressive Web Apps

2 of 23

Progressive Web Apps

3 of 23

Migrate an existing site to PWA

  1. Move to HTTPS
  2. Use caching strategies for perf and offline
  3. Implement an app shell architecture
  4. Incorporate "Add to Homescreen"
  5. Add Push Notifications, Payment API, Credentials API, etc. (if relevant)

Progressive Web Apps

4 of 23

What is an application shell?

Progressive Web Apps

5 of 23

Architectural patterns

and caching strategies

Progressive Web Apps

6 of 23

Server-Side Rendering (SSR)

  • Server returns a complete page
  • Page loads CSS, JavaScript, and all content
  • Page updates reload the DOM

Progressive Web Apps

7 of 23

Client-side rendering (CSR)

  • Server returns "template page" with CSS & Javascript
  • JavaScript makes request to get content, adds to page
  • Page updates reload only the dynamic content

Progressive Web Apps

8 of 23

Caching SSR

  • Cache common files: CSS, Javascript, common images
  • For offline use
    • If server renders static pages, cache them
    • Add code for offline mode

Progressive Web Apps

9 of 23

Detecting offline use

if (navigator.online)

or

navigator.addEventListener('online', …)

navigator.addEventListener('offline', …)

Progressive Web Apps

10 of 23

Caching CSR

  • Cache core code, CSS, and template page
  • Add code to:
    • Cache data using Cache API or IndexedDB
    • Detect when app is offline and save user actions for later replay

Progressive Web Apps

11 of 23

Fine-Tuning your App Shell

Progressive Web Apps

12 of 23

Where does the data live?

Progressive Web Apps

13 of 23

Combined strategies

  • Cache first, Network fallback
  • Network first, Cache fallback
  • Network only
  • Cache only

Progressive Web Apps

14 of 23

Special cases

  • Cache first, Network fallback
  • Network first, Cache fallback
  • Cache-Network race
  • Network only
  • Cache only

Progressive Web Apps

15 of 23

Using libraries to code service workers

sw-toolbox library

Loaded by SW at run time

Applies caching strategies to URL patterns

Installs via Bower, npm, GitHub

sw-precache

Integrates with build process

Generates SW code for caching

Maintains resources in app shell

Hooks into build process (Gulp, Grunt)

Progressive Web Apps

16 of 23

Completing your PWA

Progressive Web Apps

17 of 23

Add to Homescreen

  • Name
  • Icon
  • Startup URL
  • Display mode
  • Orientation
  • Background color
  • Theme color
  • Manifest file for Android
  • <meta> tags for others

These specify:

Progressive Web Apps

18 of 23

Push Notifications

  1. App subscribes client to a push service
  2. App receives client token
  3. Server sends request to push service using token
  4. Push service sends message to client
  5. Service worker wakes up and receives push event
  6. Service worker displays a notification

* Even when app & browser are closed!

Progressive Web Apps

19 of 23

Payments and Credential Management

  • Payment API
  • Credential Management API

Progressive Web Apps

20 of 23

Building high-performance PWAs

Progressive Web Apps

21 of 23

Recommended patterns for PWAs

  1. Client-side rendering full page (full page caching, potential for JSON payload bootstrapping via server)

In recommended order:

  1. Application shell (SSR) + use JavaScript to fetch content once the app shell is loaded
  1. Application shell (SSR both shell + content for entry page). Use JavaScript to fetch content for any further routes and do a "take over"

  1. Server-side rendering full page (full page caching)

Progressive Web Apps

22 of 23

Real world examples of PWA's

Offline Wikipedia app, a demo by Jake Archibald

Flipkart Lite, an e-commerce company

Voice Memos, a sample web app that records voice memos

AliExpress, one of the world's largest e-commerce sites

BaBe, an Indonesian news aggregator service

United eXtra, a leading retailer in Saudi Arabia

The Washington Post, America’s most widely circulated newspaper published in Washington, D.C.

Progressive Web Apps

23 of 23

Resources

Resources

Progressive Web Apps