Why should you care about Progressive Web Apps (PWAs)?

Progressive web applications (PWAs) solve many of today’s mobile-development issues

In the last few years, there has been exponential growth in the number of mobile phone users. Today, more than 60% of total internet usage is happening via mobile phone.

Obviously, the reasons include portability, cheap hardware, easy access to the internet, and the increased number of services on the internet. With more users on mobile, the optimization of user experience on the phone is essential.

For smaller companies, which often do not have native apps due to cost or time constraints, the web app is the key opportunity for winning customers by providing the best possible experience.

If companies have a dedicated native-mobile app, there’s a possibility many users will still prefer their web version in order to avoid downloading and installing an app on their phone. This could be due to hardware and memory constraints or some other personal preference.

If a company is dedicated and wants to get the maximum number of engaged customers, the experience of the web app has to be close to that of the native app.

Nowadays, the expectation from our websites is very high. Almost 25 years ago when the website was invented, its purpose was mostly to share information.

Today, the website is a grocery shop, social network, chatting place, etc. The website is expected to search for houses and hold the world map. The website is expected to give all the features of PowerPoint and Excel.

Meet Progressive Web Applications

Let’s take the example of WhatsApp on your phone. When there’s no network, you can still open the app, check past messages, and even reply to someone. When the phone gets the internet connection, the messages are being automatically sent in the background.

This is what PWA promises to provide in web apps. It enables web apps to load when there is no network, sync in the background, and seamlessly do things while providing a native-like experience for your users.

Why We Need PWAs, and What Are Their features?

Let’s discuss some of the core attributes that are missing from common nonprogressive web applications.

  1. Reliable The app should be lightning fast when loading — it should be close to instantaneous and should also open when there is no network or a fairly low-speed network like 2G. Google found that 53% of the users abandon the website if the page took longer than three seconds to load.
  2. Fast The scrolls and page transitions should be buttery smooth when the user is interacting with the web app. Everyone hates crappy scrolls.
  3. Responsive The app should fit in all the different sizes of devices. The perfect web app should be like liquid, which takes the shape of its vessel.
  4. Installable If we want to make web apps closer to the native apps, they have to be installable and should reside in the home screen along with other native apps so the user can access the PWA in one click.
  5. Splash screen
    PWAs adds a splash screen during the startup of the app. This makes the PWA feel more like a native app.
  6. Highly engageable The app should keep the users engaged. A PWA provides features like push notifications, a home-screen icon, full-screen capabilities, and an offline-first app to glorify user engagement.

All the above characteristics are possible in PWAs.

A PWA is just a regular web app which attended the best university and mastered user experience.

PWA and Modern UI Frameworks

Few people think a PWA is coupled with the latest UI frameworks like React.js, Angular 6, or Vue.js.

Well, not necessarily.

PWA has nothing to do with the framework you’re using — it only needs the required components.

How Does a PWA Make Websites Available Offline?

This was exactly my first thought when it came to PWAs. How exactly can web apps open without the internet?

We all know native apps can open without an internet connection because when we download and install them, critical resources like UI components and some data are stored in the device. Well, this is exactly what happens in a PWA as well.

The PWA stores HTML files, CSS files, and images in the browser cache, and the developers can fully control the network call. All of these are being achieved by service workers.

What Are the Technical components of a PWA?

PWAs have some important technical components that work together and energize the regular web app. The following components are required to develop a good PWA.

This is image title

Let’s get an overview of each of them.

Service worker

Our web apps talk to the network directly, and if there is no network, the screen shows the famous dinosaur.

This is image title

Screen when our normal web cannot connect to the internet

Here’s an opportunity to optimize this process. For the first-time load, the service worker stores the required resources in the browser cache. And when the user visits the app next time, the service workers check the cache and return the response to the user before even checking the network.

A_service worker_ is just a component of JavaScript code that works as a proxy between the browser and the network. A service worker manages the push notifications and helps to build the offline-first web application using the browser’s cache API.

This is image title

This is how the service worker performs its responsibility to empower regular websites

This can speed up the performance of your app, whether the device is connected or not connected to the internet.

The developer has full control over the behavior of the app and how it should respond in various scenarios. The service worker has its own life-cycle events.

This is image title

Once the caching is complete and ready for offline visits, you can also choose to brag about it by displaying a note saying that caching is complete and the user can visit this offline as well.

The manifest file

The manifest file is a config JSON file that contains the information of your application, like the icon to be displayed on the home screen when installed, the short name of the application, the background color, and the theme.

If the manifest file is present, the Chrome browser will automatically trigger the web app to install the banner. If the user agrees, this adds the icon to the home screen, and the PWA is installed. Isn’t this bossy?

The following is the sample manifest file:

{
  "short_name": "Spinner",
  "name": "Fidget spinner",
  "icons": [
    {
      "src": "/images/icons-192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "/images/icons-512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ],
  "start_url": "/home/?source=pwa",
  "background_color": "#3367D6",
  "display": "standalone",
  "scope": "/home/",
  "theme_color": "#3367D6"
}

Check the manifest file in action in the following screenshots.

This is image title

HTTPS

Service workers have the ability to intercept the network requests and can modify the responses. Service workers perform all the actions on the client side. Hence, PWAs requires secure protocol HTTPS.

The service worker has the ability to receive push notifications and background sync, which definitely increases the user experience and keeps the customer engaged. Push notifications and background sync are optional but are recommended to provide a more native-like experience.

Demo Time

Today, there are many PWAs available out there. If you want to play around with a PWA and want to see service workers in action, visit fidgetspin.xyz, and switch to the Application tab in Chrome’s DevTools.

This is image title

  1. Status: Tells us that the service worker is activated and running.
  2. Offline: By checking this option, Chrome treats the app is if it’s offline. Refresh the tab, and it’ll emulate how the PWA will respond when there’s no network. You can also switch off the WiFi or data to test the PWA.
  3. Cache: This section shows what files are stored in the cache by the service worker.
  4. Push & Sync: These sections are used during development to test push notification and background sync.

You can visit https://pwa.rocks/, which has a good collection of PWA apps.

Tools and Libraries

There are few open-source tools available that enhance and make it easy to develop PWAs.

  1. Lighthouseis an audit tool that can run against any web page, public or personal, and generates one report with the checklist required for a PWA. This can be used during the development of your PWA to crosscheck and get recommendations to further improve the experience.
  2. Workboxis a collection of libraries, open sourced by Google, and can be used to generate the service-worker file. Workbox also comes along with various caching strategies of images and other resources.

Success Stories of PWAs

Google publishes the success stories of companies that have implemented PWAs. Visit this page to read more about how companies have solved problems to handle slow networks, how they optimized the user experience, and how they got up to an 80% increase in conversions and SEO performance.

This showcases various problems faced by various companies around the globe and how they solved it using PWAs. I’m pretty sure you’ll get directions on how a PWA can prove helpful for you as well.

#programming #PWA

Why should you care about Progressive Web Apps (PWAs)?
3.65 GEEK