WIP
Lighthouse
Chrome dev tools -> Lighthouse to run an audit
- analyzes performace, accessibility, seo and determines if your app is installable as a PWA. Test at https://fireship.io/
- Trigger and test push notifications, background sync of the service worker
Workbox
Library to help build PWA’s
- Cache URL’s in your app so they can be viewed offline. Inspect the cache under chrome dev tools
Application
tab underCache Storage
. Example at https://fireship.io/
If using React or Angular
1 | npm install workbox-cli --global |
or import from CDN
1 | importScripts('cdn://workbox-sw.js') |
PWA Components
index.html
1 |
|
logo.png
Your logo bro \ :D /
manifest.json
manifest.json
Contains icons and other meta data about the app.
Icons can be created with PWA Asset generator, this will target logo.png
and output the results in the icons
directory. Additionally this will produce the content needed for the mainifest.json file (look in the terminal output)
1 | npx pwa-asset-generator logo.png icons |
Example from https://fireship.io/
1 | { |
service-worker.js
Enable caching networkFirst()
will use network first but fall back to cacheFirst
is the network is not avalible.
1 | importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.0.2/workbox-sw.js'); |
1 | npx serve |
If you are using the Create react app tool will automatically generate a service worker for you.
Service worker -> register to run in the background.
- Caching pages
- Run background sync
- Listen for push notifications
This will check if the browser supports the feature and then reginster the worker which is service-worker.js
.
Once registered it can be seen in the Application
tab in chrome dev tools.
References
- https://create-react-app.dev/docs/making-a-progressive-web-app/
- Hacker News readers as Progressive Web Apps
- https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps
- https://www.youtube.com/watch?v=sFsRylCQblw
2