PWA - The Evolution and Necessity of Progressive Web Apps
Tags: pwa, pwabuilder, frontend, development
Published: 2024-05-21 16:09:01

## Introduction

The internet officially launched on January 1, 1983, initially accessible only via desktop computers. This provided a gateway to a world of information and communication. However, with the advent of smartphones in the late 2000s, the internet became accessible from virtually anywhere, revolutionizing how we interact with digital content.

By 2014, the number of users accessing the internet via mobile apps surged dramatically. According to a report by Flurry Analytics, mobile app usage accounted for 86% of the time that U.S. mobile consumers spent on their smartphones in 2014, while mobile web usage accounted for only 14% of that time. Additionally, Smart Insights supports this claim, noting that smartphone users spent an average of 2 hours and 19 minutes per day on apps, compared to just 22 minutes on mobile web browsers.

By combining insights from these sources, it is evident that mobile apps overwhelmingly dominated internet usage on smartphones by 2014, highlighting a significant preference for apps over mobile web browsing during that period. This set the stage for the appearance of **Progressive Web App**s (PWAs) in 2015, which aim to bridge the gap between the extensive reach of web browsers and the superior functionality of native mobile apps.

Sources:
- [Mobile App Usage Increases In 2014.
](https://techcrunch.com/2014/04/01/mobile-app-usage-increases-in-2014-as-mobile-web-surfing-declines/)
- [Mobile App Statistics – July 2014 round-up.](https://www.smartinsights.com/mobile-marketing/app-marketing/mobile-app-statistics/)




## Understanding Progressive Web Apps (PWAs)
Progressive Web Apps (PWAs) are web applications that use modern web technologies to provide a native app-like experience on any device. They combine the best features of web and mobile apps to offer a seamless user experience. Key characteristics of PWAs include:
- **Offline Functionality:** PWAs can work offline or in low network conditions due to service workers that cache essential resources.
- **Installability:** They can be installed on a device's home screen directly from the browser without needing app store distribution.
- **Responsive Design:** PWAs adapt to different screen sizes and orientations, ensuring a consistent experience across all devices.
- **Security:** Served via HTTPS, PWAs ensure secure connections and protect data integrity.
- **Push Notifications:** Like native apps, PWAs can send push notifications to keep users engaged and informed.
- **Automatic Updates:** Service workers enable background updates, ensuring users always have the latest version without manual intervention.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zopekk5861syo4y38ubj.png)

## Detailed Implementation Steps
- **Stay Secure (HTTPS):**
Ensure the application is served over HTTPS to protect user data and prevent tampering.


- **Create Service Workers:**
Service workers are scripts that run in the background, managing network requests and caching for offline use. Here's a simple example of a service worker script:

```javascript
// service-worker.js
self.addEventListener('install', event => {
  event.waitUntil(
    caches.open('app-cache').then(cache => {
      return cache.addAll([
        '/',
        '/index.html',
        '/styles.css',
        '/script.js',
        '/offline.html'
      ]);
    })
  );
});

self.addEventListener('fetch', event => {
  event.respondWith(
    caches.match(event.request).then(response => {
      return response || fetch(event.request);
    }).catch(() => {
      return caches.match('/offline.html');
    })
  );
});
```

Just you need to place your service-worker.js file in the root directory of your project. This ensures that it has control over the entire scope of your app. Finally, register it in your main JavaScript file:

```javascript
if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/service-worker.js')
    .then(registration => {
      console.log('Service Worker registered with scope:', registration.scope);
    })
    .catch(error => {
      console.log('Service Worker registration failed:', error);
    });
}

```


- **Create a Manifest File:**
A manifest file is a JSON file that contains metadata about your web application, including details such as the app's name, short name, theme color, and icons. This file is crucial for making your web app installable on a user's device. You can create it manually or use online tools to generate the file. Some useful tools include:

  - [SimiCart Manifest Generator](https://www.simicart.com/manifest-generator.html/)

  - [Manifest Generator](https://manifest-gen.netlify.app/)

Example Manifest File:

```json
{
  "name": "My Progressive Web App",
  "short_name": "MyPWA",
  "start_url": "/index.html",
  "display": "standalone",
  "background_color": "#ffffff",
  "theme_color": "#000000",
  "icons": [
    {
      "src": "/images/icon-192x192.png",
      "sizes": "192x192",
      "type": "image/png"
    },
    {
      "src": "/images/icon-512x512.png",
      "sizes": "512x512",
      "type": "image/png"
    }
  ]
}

```

.  **name and short_name:** The name and short name of your app.
.  **start_url:** The URL that the app should start at when launched.
.  **display:** Defines the mode in which the PWA will be displayed (e.g., standalone, fullscreen).
. **background_color:** The background color of the splash screen.
.  **theme_color:** The color of the app’s toolbar.
.  **icons:** Array of icons for the PWA in different sizes.

Save the manifest.json file in the root directory of your project or in a directory that you can reference directly.
Finally, ensure you link the manifest file in the `<head>` of your HTML:

```html
<link rel="manifest" href="/manifest.json">
```

- **Ensure Responsiveness:**
Use CSS media queries and flexible grids to design the app for various screen sizes and orientations.


- **Optimize Performance:**
Techniques such as lazy loading, code splitting, and efficient caching are essential. Tools like Lighthouse can audit and suggest performance improvements.


- **Enable Push Notifications:**
Implement push notifications using the Push API and service workers to re-engage users with timely updates.




## Examples and Impact of PWAs
Several notable companies have adopted PWAs and witnessed significant improvements in user engagement and performance:

- **Twitter Lite:** After launching its PWA, Twitter experienced a 65% increase in pages per session, a 75% increase in Tweets sent, and a 20% decrease in bounce rate.
- **Starbucks:** Starbucks saw a 2x increase in daily active users with its PWA, allowing customers to browse the menu, customize orders, and add items to their cart, even offline.
- **Trivago:** The travel booking platform achieved a 150% increase in user engagement with its PWA, providing a seamless experience across all devices.
- **Pinterest:** Pinterest's PWA led to a 60% increase in core engagement and a 44% increase in user-generated ad revenue.

These examples highlight the transformative impact PWAs can have on user experience and business metrics.


## Useful and Helpful Links
To further enhance your understanding and implementation of Progressive Web Apps (PWAs), here are some valuable resources:

- [web.dev - Progressive Web Apps:](https://web.dev/explore/progressive-web-apps?hl=fr) Comprehensive guides and best practices for building high-quality PWAs, focusing on performance, reliability, and user engagement.

- [MDN Web Docs - Progressive Web Apps:](https://developer.mozilla.org/fr/docs/Web/Progressive_web_apps) Detailed documentation from Mozilla on PWA technologies and implementation techniques, ideal for both beginner and experienced developers.

- [PWA Builder Docs - Adding a Web Manifest:](https://docs.pwabuilder.com/#/) Step-by-step guide on adding a web manifest to your existing app, crucial for making your PWA installable.

- [PWA Builder:](https://www.pwabuilder.com/) A tool that simplifies the process of converting websites into PWAs by generating essential components like service workers and manifest files.

- [Visual Studio Marketplace - PWA Studio:](https://marketplace.visualstudio.com/items?itemName=PWABuilder.pwa-studio) An extension for Visual Studio that helps developers create and optimize PWAs directly within their development environment.

These resources provide essential tools, documentation, and best practices to help you effectively develop and deploy Progressive Web Apps, ensuring a seamless, app-like experience for users across all devices.


## Conclusion
In today's digital landscape, the necessity of using Progressive Web Apps cannot be overstated. They offer the reliability, speed, and engagement of native apps while maintaining the broad reach and accessibility of web applications. PWAs are not just a trend but a fundamental shift in how we approach web and mobile application development. By embracing PWAs, businesses can deliver superior user experiences, drive engagement, and stay competitive in an ever-evolving digital world. It's time to harness the power of PWAs and redefine the boundaries of what's possible on the web.