Pwas (short version)

PWAs (short version)

tutorial

From web app to PWA app

what's a PWA? simply a web app + these features:

1. write your webapp

can be anything, generally a html and css and optionally some js, inline or external push to somewhere (e.g. firebase)

2. add a service worker

a service worker is a js file that performs some tasks like caching, push notifications plus more (read below)

add a service worker (a js file with functions) as well as point to the service worker in the html

service worker yay

3. create an icon (!?)

k then.

outputs : png formats

4. create a manifest

outputs : manifest.json, an additional line in html linking to manifest.json

5. Push Notifications

testing your push notifications

follow this: link

outputs : additions to index.html

the current deploy (20180405) will react to this curl from terminal

curl -X POST -H "Authorization: key=AIzaSyAkRH6MMhLRNpK8JUEc6eR-Y3vzL_aV4L0" -H "Content-Type: application/json" -d '{
  "notification": {
    "title": "Hello World PWA",
    "body": "Hi",
  },
  "to": "dXayu72QAlo:APA91bGgh7Kzrol91H8cvdKCDzM9LuRSlgC8kXjxJaZ71ksoVNt7HT3Rc1pu3jn3zzxl0zXzYq82A9dM8GrWbJYdYknmOTBZgbIZLGvEfmEAf5RuPv5-NzNPFW75ADoO2l3TzAmDe8fX"
}' "https://fcm.googleapis.com/fcm/send"

what are service workers?

a service worker is a programmable network proxy that sits in between the page (user) and the server, allowing you to control how network requests from your page are handled.

because it can do injections through 'man-in-the-middle' attacks, which is a BAD THING service workers only run over HTTPS.

the service worker becomes idle when not in use and restarts when needed. so a global state DOES NOT persist between events. to store info that persists between restarts, use IndexedDB databases.

service workers make extensive use of promises.

service workers are not blocking (designed to be fully async).

service workers can receive push messages from a server when the app is not active (when it is not open, like a proper native app) (subject to different browser implementations on differnet OSes)

service workers cannot access the DOM directly. it uses the postMessage() method to send data and a 'message' event listener to receive data.

yes things

no things