Zero to 15 — Building a Nothing PWA in 15 minutes
Tags: pwa, web, netlify
Published: 2018-08-15 02:22:52


---
title: Zero to 15 — Building a Nothing PWA in 15 minutes
published: true
description: Learn how I build a “Nothing” Progressive Web App in 15 minutes
cover_image: https://i.imgur.com/PVmTXL1.jpg
tags: pwa, web, netlify
---

### What’s Nothing?

![](https://cdn-images-1.medium.com/max/1000/1*XZkZE7VkNnfQ5q18LpMBow.jpeg)

The [original version of the “Nothing”](https://play.google.com/store/apps/details?id=com.gorro.nothing) Android App was developed by Chilango Lab and it has more than 1 million downloads and 4.2 stars rating on Google Play Store 🎉.

The Nothing Android App basically does nothing, except there’s a very cool easter egg in the app ( ͡° ͜ʖ ͡°).

However, the APK size of the Nothing Android App is 14MB and it uses 19.24MB of the phone storage after the installation. So it makes me think, is there any way I can make it smaller?

![](https://i.imgur.com/q5w89SW.png)
*(Left) Nothing Android App: 19.24MB — (Right) Nothing Progressive Web App: 205KB*

The solution is simple. I can rebuild the whole thing using HTML, CSS, and JavaScript. To bring it to the next level, I can upgrade it to a [Progressive Web App (PWA)](https://developers.google.com/web/progressive-web-apps/), so users can run it without an Internet connection and also able to add the PWA to their home screen.

### 👩🏻‍🎨 Icon Design

Before I start to talk about the code, let’s design an icon for the Nothing PWA! The tool I am using to generate the app icon is called [Launcher Icon Generator](https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html). It’s a very astonishing [open source](https://github.com/romannurik/AndroidAssetStudio) tool developed by [Roman Nurik](https://twitter.com/romannurik).

![](https://cdn-images-1.medium.com/max/1000/1*IlOsAMmxr7AUcq2K5maV9Q.png)

With the Launcher Icon Generator, I am able to design and generate the app icon (with Material Design?) for the Nothing PWA in no time. The generator will automatically generate the icon in different sizes: 48px, 72px, 96px, 144px, 192px and 512px.

### **PWACompat**

Now I have the app icons ready, the next step is to create a [Web App Manifest](https://developers.google.com/web/fundamentals/web-app-manifest/). With that, Chrome for Android will automatically shows a splash screen while loading the PWA. However, is there any way I can bring this splash screen feature to other older browsers?

Meet [PWACompat](https://github.com/GoogleChromeLabs/pwacompat), PWACompat is a library that brings the Web App Manifest to non-compliant browsers for better Progressive Web Apps.

The library is very straightforward, just add the Web App Manifest file and the PWACompat script, and you are good to go!

    <link rel="manifest" href="manifest.json" />
    <script async src="https://cdn.jsdelivr.net/npm/pwacompat@2.0.6/pwacompat.min.js"
        integrity="sha384-GOaSLecPIMCJksN83HLuYf9FToOiQ2Df0+0ntv7ey8zjUHESXhthwvq9hXAZTifA"
        crossorigin="anonymous"></script>

![](https://cdn-images-1.medium.com/max/800/1*P4zvXn8iAjhAE9PYEEU9qQ.gif)
*Splash screen on Safari (iOS)*

Tadah! Just like that, I managed to bring the splash screen to older browsers. However, is that all what PWACompat can do? No! It actually can do more!

PWACompat also creates meta icon tags for all icons in the manifest (including favicon), creates fallback meta tags for various browsers describing how a PWA should open, and also sets the theme color based on the web app manifest.

### 🏠 Add to Home Screen

One of my favorite feature I get from Progressive Web App is Add to Home screen (A2HS). However, starting in Chrome 68 on Android, [Chrome will show the A2HS mini-infobar instead of the big A2HS banner](https://developers.google.com/web/updates/2018/06/a2hs-updates):

![](https://cdn-images-1.medium.com/max/800/1*3GwP3kbKBFSedyTaI4NWZQ.png)
*😵 RIP the old A2HS banner (Chrome 67 and before)*

Nonetheless, the A2HS mini-infobar is an interim solution, it will be removed from Chrome someday in the future. Hence, I should provide a better A2HS UX to the Nothing PWA.

![(Left) Install Button — (Middle) Install Button + A2HS Mini-Infobar — (Right)
A2HS Dialog](https://i.imgur.com/6GwUIXc.png)
*(Left) Install Button — (Middle) Install Button + A2HS Mini-Infobar — (Right)
A2HS Dialog*

In this case, if the browser supports the Add to Home screen feature, then it will display an “Install” button at the top of the page. When the user clicks on the install button, it will trigger the A2HS Dialog.

```
var installPromptEvent;
var btnInstall = document.querySelector('#install');

window.addEventListener('beforeinstallprompt', function (event) {
    event.preventDefault();
    installPromptEvent = event;
    btnInstall.removeAttribute('disabled');
});

btnInstall.addEventListener('click', function () {
    btnInstall.setAttribute('disabled', '');
    installPromptEvent.prompt();
    installPromptEvent.userChoice.then((choice) => {
        if (choice.outcome === 'accepted') {
            console.log('User accepted the A2HS prompt');
        } else {
            console.log('User dismissed the A2HS prompt');
        }
        installPromptEvent = null;
    });
});
```

<span class="figcaption_hack">The browser will fire a `"beforeinstallprompt"` event is the site meets the Add to Home screen criteria</span>

### 🥚 Easter Egg

![Spoiler Alert !!!](https://cdn-images-1.medium.com/max/1000/1*ePTthP8JcXDteH9p7G8gqQ.jpeg)
*Spoiler Alert !!!*

Here is the easter egg of the Nothing PWA: Konami Code + [10 hours YouTube video](https://twitter.com/Nick_Craver/status/720062942960623616).

![⬆️⬆️⬇️️⬇️⬅️➡️⬅️➡️👆🏻👆🏻](https://cdn-images-1.medium.com/max/600/1*9f-Coe9dfwz_UmlsTUmHjA.gif)
*⬆️⬆️⬇️️⬇️⬅️➡️⬅️➡️👆🏻👆🏻*

Once the user successfully complete the Konami Code, the Nothing PWA will redirect the user to a [YouTube video](https://stackoverflow.com/admin.php).

For the Konami Code, I am using this library: [Konami-JS](http://snaptortoise.github.io/konami-js/). It’s lightweight and easy to implement. Furthermore, this library works on mobile too! The only drawback is, the Konami Code will become “up, up, down, down, left, right, left, right, tap, tap”.

#### Disable Pull to Refresh

However, there’s a small problem. When user trying to swipe down the page on mobile, it will trigger the “pull-to-refresh” action.

![](https://cdn-images-1.medium.com/max/800/1*cDXJ33JdnhzIUfzy8R_14g.gif)

The good news is, we can disable the pull-to-refresh action [with a single line of CSS](https://developers.google.com/web/updates/2017/11/overscroll-behavior): `overscroll-behavior-y: contain`.

### **☁️ Hosting**

The Nothing PWA is hosted on Netlify. Netlify is an all-in-one platform for automating modern web projects.

The reason I choose to host the Nothing PWA on Netlify is, it’s very easy to setup. Not to mention, Netlify is free to use!

![Netlify Dashboard](https://cdn-images-1.medium.com/max/1000/1*xLFM3ifLVb5X63Nj7XZHUw.png)
*Netlify Dashboard*

For site deployment, you have three methods you can choose from: via the command line tools, manual deployment or continuous deployment.

**Command Line Tools**

This is basically the most classic way to deploy a site. Install the [Netlify CLI](https://github.com/netlify/netlifyctl), log in to your Netlify account, initialize the project, and you are ready to deploy the site to Netlify.

    > brew tap netlify/netlifyctl 
    > brew install netlifyctl
    > netlifyctl login
    > netlifyctl init
    > netlifyctl deploy

**Manual Deployment**

This method is basically the most effortless way for anyone want to deploy their site: Drag & Drop.

![](https://cdn-images-1.medium.com/max/1000/1*8eB2dwalDXgHBHR4Pm83Iw.png)

This feature is so cool that I wish Firebase could implement this. Simply drag and drop your project folder and you are ready to go!

**Continuous Deployment**

This is the method I am currently using for this project. Once my GitHub repository is linked to Netlify, whenever I push the code to the git repository, Netlify will automatically build and deploy the site, just like magic 🧙🏻‍.

#### 🔒 HTTPS!

Since Progressive Web Apps must be served from a secure origin, I need to make sure the site has HTTPS enabled. The good news is, Netlify provides free HTTPS for everyone including custom domain.

![](https://cdn-images-1.medium.com/max/1000/1*cu1Zs1B4ziZFkJVXj7lwTA.png)

Moreover, you also can enable force HTTPS ([HTTP Strict Transport Security](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security), HSTS) from the Netlify dashboard. This will ensure the site is always protected by HTTPS.

### 💡Lighthouse

[Lighthouse](https://developers.google.com/web/tools/lighthouse/) is an open-source, automated tool for improving the quality of web pages. You can run it against any web page, public or requiring authentication. It has audits for performance, accessibility, progressive web apps, and more.

![](https://cdn-images-1.medium.com/max/1000/1*85AX9Hs1Tty316wkADoifQ.png)

Not bad huh? I managed to get 97 for performance, and 100 for PWA, accessibility, best practices and SEO. 🔥

You can view the full Lighthouse report here:
[https://builder-dot-lighthouse-ci.appspot.com/report.1533954675085.html](https://builder-dot-lighthouse-ci.appspot.com/report.1533954675085.html)

*****

### 🎉 Try It Now

![](https://cdn-images-1.medium.com/max/800/1*hA7rq9gWv2ea6UEIwMIDOw.gif)
🚀 You can try the Nothing PWA here: [nothing.limhenry.xyz](https://nothing.limhenry.xyz/)

The source code is also available on GitHub: [nothing.limhenry.xyz](https://github.com/limhenry/nothing)