What is a Progressive Web App?
Progressive web apps are mobile websites that are built using web technology, but it acts and looks like a mobile application. Recent improvements to the browser and the availability of service workers, as well as the Cache and Push APIs, have allowed web developers to allow users to install web applications on their home screen, receive push notifications, and even work offline.
Why use PWA?
- Add Home screen icon to load the app fullscreen
- Manages cache
- App loads quicker
- Ability to access with an inconsistent network connection.
- Send push notifications
- Periodic sync – Use the app offline and let it continue with the process when able to acquire a connection
Developing a basic PWA
*Progressive Web Apps must be served from a secure origin (https).
To begin with, this will be file structure:
![Progressive Web App (PWA) PWA file structure](https://synceight.com/wp-content/uploads/2020/04/image2018-6-6_16-43-19.png)
Generating the icons and manifest file
The icons to match all devices and the manifest can be created on https://www.favicon-generator.org/.
- Upload the logo and generate the files.
- Download the generated files.
![Progressive Web App (PWA) Generated PWA files](https://synceight.com/wp-content/uploads/2020/04/image2018-6-6_16-47-32.jpg)
Creating the App
- Add the downloaded images to the project image folder
- Add the manifest file to the root
- Copy the above-given code(path of the icons and manifest) and paste it in the head of your HTML. Update the file paths
![Progressive Web App (PWA) Generated code added to the site head](https://synceight.com/wp-content/uploads/2020/04/image2018-6-6_16-56-10.jpg)
- Edit the manifest file to add a name, short_name, start_url, display, background_color, theme_color, lang, and the icons.
*It’s required to have those
![Progressive Web App (PWA) PWA sample manifest file](https://synceight.com/wp-content/uploads/2020/04/image2018-6-6_16-54-47.jpg)
- You can test your manifest file. (Chrome inspect → Application). Under the application, you can find a tab name manifest.
![Progressive Web App (PWA) Manifest showed in Chrome Dev Tools](https://synceight.com/wp-content/uploads/2020/04/image2018-6-7_10-32-55.jpg)
Adding the Service worker
You can download a sample service worker code from https://www.pwabuilder.com/serviceworker.
- Select the type of service worker functionality for the app
- Add the “Code for the website” at the bottom of the index file. This will register the service worker.
![Progressive Web App (PWA) Registering service worker](https://synceight.com/wp-content/uploads/2020/04/image2018-6-7_10-17-22.png)
- Create a js file in the root and replace ‘pwabuilder-sw.js’ with the name of the created file.
- Add the “Service worker code” to the newly created js file.
![Progressive Web App (PWA) Sample service worker code](https://synceight.com/wp-content/uploads/2020/04/image2018-6-7_10-21-43.png)
- You can test your service worker. (Chrome inspect → Application). Under application, you can find a tab name service worker.
![Progressive Web App (PWA) Service worker defined in Chrome Dev tools](https://synceight.com/wp-content/uploads/2020/04/image2018-6-7_10-47-36.jpg)
- Also, tick the Offline checkbox and you will be able to navigate through the site. (This will vary on your caching definition in service worker js file).
Here’s a lighthouse generated report on your mini-project of progressive web apps.
![Progressive Web App (PWA) Chrome progressive web apps scores](https://synceight.com/wp-content/uploads/2020/04/image2018-6-7_10-50-50.jpg)
Leave a comment