Progressive Web Applications are absolutely awesome and they will just get better and better. In my previous post I have shown how to implement caching using a ServiceWorker. Working offline is a big chunk of PWAs, now let’s add the missing pieces.

Get started

To kickstart this project, I’ve cloned the repository of the “Implementing a Service Worker” post. To get the initial state check out pwa-start tag of this new repository.

As I said, with this we already done a big part of the PWA development, as this small application works offline. Let’s see what else is needed to make it a Progressive Webb Application.

Manifest file

One of the core concepts of a Progressive Web Application is the manifest file. This is the JSON file which configures the application and this is a big part of what makes a Single Page Application a Progressive Web Application. This is where you define the theme color of the application, add icon which can be shown while the application is loading, define how the application should be displayed and even add reference to the native application if you have one available in an app store.

First I create the manifest file and will call it manifest.json. The name is otherwise up to you, but this one seems to pretty well describe what this file is.

This is enough to get it started. For the details on the available configuration options check out the MDN site of PWA manifests. The different sized logo images I have generated using Gulp, which is not in scope of this post, but I leave a piece of code here if you need it (click to open).

Link the manifest

Now the manifest file looks good, but it floats in the nihil. To attach it to the application, update the HTML file with a link:

And that’s almost it, now just need to make sure, that the browser’s address bar will match the theme color of the application. As it should happen already before the manifest was loaded, this information also goes to the HTML file.

What have I done?

In its most basic form, that was it. We have an arguably useless web application, which works offline, customizes how the browser displays it and can be added to the home screen on Android devices and according to the news, recently iOS support also arrived.

So let’s see how it looks if I remote debug it on my device:

Screen shot of the application on an Android deviceScreen shot of application icon on Android home screen

Let’s just say, that my choice of color was brave, but other than that, it looks pretty cool, huh? The address bar of the browser became this lovely babyblue, the visitor has the option to install the application and once it’s done, there is an app icon on the home screen. Of course it also works offline, because we cached everything in the previous post.

If you start the application from the home screen, it will be started in a standalone mode, without displaying the address bar, so your application can take all the screen.

Important note: the browser may still decide, that for security reasons it falls back to a display mode which shows the address bar, so the user can see the URL. If you serve your application properly from a secure (HTTPS) URL, it should be displayed in standalone mode though if you use Chrome. Check out this W3C page for more details in the fallback display mode.

That’s it in a nutshell, hope you found it useful and feel free to ask if something was not that clear.




Tagged with