This is part 2 of the series “Hello Progressive Web App”.
Table of Contents
- Service Worker
- Caching Strategies
The manifest of a web app is a JSON file which provides information about that app.
Here’s an example of a basic manifest.json:
Most of the attributes are self explanatory. The ‘start_url’ defines where the application lives. Relative parts in this attribute start from the manifest’s location.
Setting ‘display’ to ‘standalone’ means that when launching the app from the homescreen it will look like a native app. If you want your app to open in a browser, you may set ‘display’ to ‘browser’.
All the possible attributes are described in more detail here.
To be able to add our app to the homescreen we need to provide a set of icons of various sizes. All of them have to be named properly and added to the manifest.json. This can be quite the task if you were to do it all yourself. Luckily there’s a brilliant little tool that takes away most of the pain!
With the Manifest Builder you only need one 512×512 pixel icon. It will not only scale that to all the other resolutions but also – as the name suggests – generate a nicely formatted manifest.json!
Now that we have a proper manifest, we have to link it to our application. This is crucial as it lets the browser know this is not a regular website but an application. This is done in the index.html:
Pretty much basic HTML-layout. Linking the manifest is done in a single line, there’s nothing more to that. But since we’re already here, there are some tags to be added if you want the “Add to homescreen”-feature for Safari on iOS.
Linking the stylesheet is optional, of course. It’s not required by the PWA.
Adding a manifest is essential for the app to be recognized as ‘more than a website’. Now that we have it in place, let’s dive into a bit more complex stuff with the service worker!