Introduction

As a developer, by my nature, I'm really eager for code reuse and for different kind of universal approaches.

When I first heard about Progressive Web Applications I exclaimed: "This is it! That's how application development should look like". Truly cross-platform development, one solution for every platform, from mobile to desktop. Fast, offline, responsive, installable and many more.

Then I decided to build my very first PWA! In this post, I want to share all my findings which accumulate my experience with Progressive Web Applications. Let's the story begin.

PWA

I want to start from the definition of what is actually Progressive Web Applications. First of all, PWA is not a programming language and not a framework; it's a set of web standards. For better understanding what it is, read the PWA characteristics below:

Basically, in a few words, you can transform your website and use as "native" mobile/desktop application with all advantages like offline work, push notifications, standalone mode, etc.

10 Progressive Web Applications that you can use right now

Did you become Interested? Let's check it out who on the market has PWA already. Below, I gathered the list of most prominent Progressive Web Applications which you can try right now:

  1. Twitter https://mobile.twitter.com/

  2. Uber https://m.uber.com/

  3. Google Photos https://photos.google.com/

  4. Instagram https://www.instagram.com/

  5. Starbucks https://app.starbucks.com/

  6. Tinder https://tinder.com/

  7. Fandango Movies https://mobile.fandango.com/

  8. OLX https://www.olx.in/

  9. Pinterest https://www.pinterest.com/

  10. Telegram https://web.telegram.org/

Success stories

Here I would like to showcase some success stories, how PWA can transform the business:

Twitter Lite

Twitter Lite (PWA) saw a 75% increase in Tweets sent, 65% in pages per session, and a 20% decrease in bounce rate.

PWA version of Twitter is now the fastest and most reliable way to use Twitter. The web app rivals the performance of the native app but requires less than 3% of the device storage space compared to Twitter for Android devices.

Uber

Uber’s PWA is designed to be fast even on 2G network. The core app is only 50KB gzipped and takes less than 3 seconds to load on 2G (250kB/s, 300ms latency) networks.

Pinterest

Pinterest rebuilt its mobile website as a Progressive Web Application. Weekly active mobile users have increased 103 percent year-over-year overall. Session length increased by 296 percent, the number of Pins seen increased by 401 percent. Logins increased by 370 percent and new signups increased by 843 percent year-over-year.

Since Pinterest shipped the new web experience, PWA has become the top platform for new signups. Less than 6 months since fully shipping, they had 800 thousand weekly users using PWA like a native app (from their home screen).

Tinder

Tinder reduced load time from 11.91 seconds to 4.69 seconds with their new Progressive Web App. The PWA is 90% smaller than Tinder’s native Android application. User engagement is up across the board on the PWA.

Minimal Progressive Web Application

Building a simple PWA is not rocket science. Consider the example below as "Hello World" application. For the minimal Progressive Web Application, we need the following:

manifest.json

You can think of Web App Manifest file as a collection of properties for your application. Here you can specify the name of your app, start URL, icons for pinning to home screen, colors of a splash screen and status bar and many many more. This is not a complete list of what you can do, just the minimum one. To see all properties, please read the official specification.

{
 "name": "First PWA",
 "short_name": "PWA",
 "start_url": "/",
 "display": "standalone",
 "theme_color": "#ffffff",
 "background_color":"#ffffff",
 "icons": [
   {
     "src": "logo-512.png",
     "sizes": "512x512",
     "type": "image/png"
   }]
}

serviceworker.js

As you should already know, a service worker is a piece of javascript code that your browser runs in the background and separate from the web page. As for today, it can perform such operations like push notifications and background sync. In the example below, we will cache index.html file, that will enable offline mode for your first PWA application.

// "Install" event handler will be invoked only once when you first time navigate to the page
self.addEventListener('install', function(event) {
 event.waitUntil(
   caches.open('app-cache').then(function(cache) {
     // Adds index.html page to the cache
     return cache.add('index.html');
   })
 );
});

// Will be invoked for every network call: XHR, static resources, etc.
self.addEventListener('fetch', function(event) {
 event.respondWith(
   // For every request checks matching value in the cache
   caches.match(event.request).then(function(response) {
     // Returns cached response; otherwise, makes an actual network call
     return response || fetch(event.request);
   })
 );
});

If you would like to dive deeper into service worker development, please read the official specification.

index.html

Finally, the last piece to tie everything together. Here you can find a link to manifest file. Using feature detection approach, we register service worker script.

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#ffffff">
    <link rel="manifest" href="/manifest.json">
    <title>First PWA</title>
  </head>
  <body>
    <h1>Hello PWA!</h1>
    <script>
      if('serviceWorker' in navigator) {
        navigator.serviceWorker.register('/serviceworker.js');
      }
    </script>
  </body>
</html>

Congratulations, now you should understand the core principles of building PWA. Let's move on!

My experience

When you start learning a new technology, what do you usually make? "Hello World" or something similar, right?

In my case with PWA, I decided to make something more complicated. Please meet MultiCalc - a powerful, modern, multifunctional calculator made for everyone.

Multicalc

The project was implemented using Angular 7 and TypeScript. For hosting, I chose Azure Storage (Website feature) + Verizon CDN for SPA rauting. In terms of PWA features like service workers, I didn't do almost anything, Angular framework took care for most of the part.

After almost 5 months of development, the project has been done. In general, it was straightforward. Most of the difficulties were related to the responsiveness of UI and debugging, especially for iOS devices. What works on Chrome is not necessarily going to work on Safari. Here there is a lifehack how to make your life easier with remote Safari debugging using Chrome dev tools.

I had a similar project written on C# + UWP, I would say PWA version using TypeScript looks even better and has less code. Angular + PWA is my new favorite combination for desktop/mobile/web apps development.

Overall, it was an exciting journey and I'm extremely happy with the result!

Current browsers support

This is not a complete list of PWA features. On the table below I listed only the most important ones.

Service Workers Web App Manifest Push Notifications
Chrome yes yes yes
Edge yes no yes
Firefox yes no yes
Safari yes no no

Web App Manifest is supported only on Chromium-based browsers, but it's not a big deal since you can substitute some of those features using HTML meta tags like it's done on Safari. Push notifications are not supported only on Safari and unfortunately, there is no workaround for this.

What web apps can do today

To understand your potential with PWA and what you can do and what not, we need to research available web standards and their support by modern browsers.

What you can: audio & video capture, advanced camera control, recording media, real-time communication, local notifications, push messages, home screen installation, offline mode, background sync, payments, credentials, bluetooth, USB, offline storage, geolocation, device position & motion, online state, vibration, battery status, speech recognition, clipboard, fullscreen, screen orientation & lock.

What you can't: inter-app communication, contacts, SMS, task scheduling, geofencing, proximity sensors, NFC, ambient light, wake lock, virtual & augmented reality, MIME-type handling, web share target.

By the time of reading this post, the information above can be outdated. To check the current status of web standards supported by your browser go to What Web Can Do Today.

Performance

You may think that PWA mobile development is only good for small start-ups and rapid prototyping. You can say that it's not possible to achieve the same level of performance as native applications. Yes, you are right, but in most cases with proper optimizations, you can expect more than enough from PWA in terms of speed.

To confirm my words I encourage you to check your phone for the presence of the following applications: Netflix, Instagram, Evernote, Twitter, Amazon, Uber. You might be surprised, but those apps are not native, they are hybrid applications. Hybrid apps run inside a native container and leverage the device’s browser engine to render the HTML and process the JavaScript locally. A web-to-native abstraction layer enables access to device capabilities that are not accessible in mobile web applications. Because hybrid apps consist from HTML and javascript you may expect the same level of performance for PWA.

Hybrid Applications vs PWA

Since we already touched hybrid application it's worth to compare them with PWA. I would say that PWA is the closest relative for hybrid applications and even its evolution. PWA takes hybrid apps farther.

Hybrid Applications

PWA

App stores

Ok, we are not living in an ideal world. To cover more audience, you may still want to publish your PWA to app stores even that you don't have to since your application can be installed without them. I have good news for you; you can do it with minimum efforts.

Google Play Store

In order to publish PWA to Google Play store, you still need to create a package but don't worry; you don't need to author any Java code. Google has an answer for that with Trusted Web Activities. This feature is available starting Chrome 72. Trusted Web Activities are a new way to integrate your web-app content such as your Progressive Web Application with your Android app using a protocol based on Custom Tabs.

The detailed instruction on how to use it, you can find here.

Windows Store

There are two options for getting your PWA to Windows Store:

  1. If your PWA meets specific criteria, it can be indexed by Bing search engine automatically.

  2. Manual submission which is similar to Google Play store, but even simpler, since you don't need to mess with establishing trust between application and website.

Both scenarios fully covered in the following link.

Apple App Store

It's not a secret that Apple is way behind others with web standards support for their browser Safari. PWA app store submission is not straightforward as well. To publish your web app you need to create a hybrid application with web view control to display your website. This is the most difficult solution compare to other stores since it requires writing some code.

Amazon App Store

If you didn't know, Google Play Store is not the only store where you can publish applications for Android. Another popular store is from Amazon. And it offers the easiest approach, where for submission you need to provide the URL for your Progressive Web Application. No package creation needed!

Appscope

This is an example of the app store completely dedicated to PWA. Appscope is a directory of Progressive Web Apps, showcasing the best PWA examples. All apps listed run entirely in the web browser and launch instantly without an app download. If you wish, they can be saved to your home screen just like any other app. The submission process is straightforward and does not require uploading any packages.

If you still think it's too difficult, check PWABuilder portal where projects for app packages can be created for you for free. PWA Builder was founded by Microsoft as a community guided, open source project to help move PWA adoption forward.

What’s next?

I believe that PWA is the future of mobile development where will not be any differences between native and web applications. What you can do today with Progressive Web Applications is impressive but the future is even brighter.

Google on Google IO '19 conference revealed some upcoming great features for Chrome browser which will move PWA even further: native file system access, unlimited quota, contacts picker, MIME-type handlers, SMS-based authentication, wake lock, web share target and more.

Some of those features can be already implemented when you read this post.

Learning resources