Manifest File In Progressive Web App

In this article, we will learn what is the purpose of manifest.json file in a Progressive web application.

In simple terms, Manifest is a JSON file that allows the users to install a web application to the mobile home screen without needing to go through the Play Store or App Store and install it.

With the help of manifest file, the developer can control the look and feel of the application when it is used through the mobile home screen. For example, developer can display the native like splash screen in their PWA application whenever it is launched, or the icons that are displayed when any native application is installed from the app store and so on. All these things can be controlled and can be implemented through the manifest file. In order to implement these features, we need to use some of the pre-defined properties in our manifest file. Let’s discuss them first and then we will see how each of this works with the help of an example.

  1. name property – This property is used to display the name or full name of the application in the splash-screen.

    Progressive Web App
  2. short_name property – This property is used to display the name of the application when user adds an application to the home screen.

    Progressive Web App
  1. icons property – Whenever we install any native application from the store, short name with the app icon is installed. We can achieve the same thing for a PWA using the icons property. This property expects an array of icon object. Each object is separated by comma. There are three important properties that each icon object expects i.e. src, type, and sizes.

    • In src property, pass the full image source.
    • In type property, pass the image type i.e. PNG or JPEG.
    • In sizes property, pass the image size.

      NOTE -
      Depending on the screen size where the app is installed or added, the icon    for the app is used.
  1. background_color property – This property is used to set the background color of the splash screen.
  2. orientation – We can control the orientation of our application using this property. We can set it to portrait, or landscape.
  3. start_url – This property is used to set the default page that will be displayed whenever a user launches the application.

    NOTE – If user pins any specific page from a PWA then the default page will not be triggered, meaning it will launch that specific page and not the default page.
  1. display – In a native application, there is no browser UI but since our application is a web application, so whenever user installs it or add to the home screen, the default browser will also be displayed whenever the application is launched.

    Progressive Web App

If you want to override this rule, set the display property to standalone. It will hide the browser UI.

Progressive Web App

There are few more properties like theme_color using which you can change the theme or the color of the top bars, or the related_applications property using which you can redirect the user to the native mobile application if you any in the play store.

For more information, please check this link.

Now, let’s see how to create and implement a manifest file but before moving any further please download this starter pack.

Once you have downloaded the pack, extract and open it in vscode, open the terminal using CTRL + ` command and type npm install. You can also right-click on the Package.json file and click on install dependencies.

Progressive Web App

It will download the dependencies. Once the download is complete, type npm start.

Progressive Web App

Press Enter and you will see the following –

Progressive Web App

Open Google Chrome and type – localhost:8081 and press Enter.

Progressive Web App
At the moment, we don’t have any manifest, so let’s add one in our project.

Inside the public directory, create a new file and name it manifest.json.

Progressive Web App

In the Index.html page add the reference to the manifest file.

  1. <link rel="manifest" href="/manifest.json">  

Add the following in the manifest.json.

  1. {  
  2.     "name""Blog and Share your Knowledge",  
  3.     "short_name""Blogger",  
  4.     "display""standalone",  
  5.     "start_url""/index.html"  
  6. }  

Run the application using the npm start command. Once the application is displayed open developer tools and navigate to the Application section and click Manifest.

Progressive Web App

Look at the identity and presentation section in the App Manifest. You will notice the value of name, short name is the same as that of what we have provided in our manifest file, and same for the start URL and display. At the moment we haven’t specified any theme or background color or the icons. So, let’s add them.

  1. {  
  2.     "name""Blog and Share your Knowledge",  
  3.     "short_name""Blogger",  
  4.     "display""standalone",  
  5.     "start_url""/index.html",  
  6.     "background_color""#34495e",  
  7.     "theme_color""#8e44ad",  
  8.     "icons": [{  
  9.         "src""src/images/open-book16.png",  
  10.         "type""image/png",  
  11.         "sizes""16x16"  
  12.     }, {  
  13.         "src""src/images/open-book24.png",  
  14.         "type""image/png",  
  15.         "sizes""24x24"  
  16.     }, {  
  17.         "src""src/images/open-book32.png",  
  18.         "type""image/png",  
  19.         "sizes""32x32"  
  20.     }, {  
  21.         "src""src/images/open-book64.png",  
  22.         "type""image/png",  
  23.         "sizes""64x64"  
  24.     }, {  
  25.         "src""src/images/open-book128.png",  
  26.         "type""image/png",  
  27.         "sizes""128x128"  
  28.     }, {  
  29.         "src""src/images/open-book256.png",  
  30.         "type""image/png",  
  31.         "sizes""256x256"  
  32.     }, {  
  33.         "src""src/images/open-book512.png",  
  34.         "type""image/png",  
  35.         "sizes""512x512"  
  36.     }]  
  37. }  

Run the application and now you will also see theme color, background color and icons.

Progressive Web App

Now let’s test this application in android emulator.

Launch an android emulator and open google chrome.

If you don’t find chrome in your emulator, please check this link

Type this address - 10.0.2.2:8081

Progressive Web App

Press Enter.

Progressive Web App
So, our application works on the mobile browser without any issue. Let’s add this application to the home screen.

Click the icon on the right.

Progressive Web App

Click on Add to Home screen

Progressive Web App

The icon is picked up by the browser automatically, and look at the name, it is the same name that we have provided in the short_name property in the manifest.json file.
Progressive Web App
You can change the name.

Progressive Web App

Click Add.

Progressive Web App

Once you see this icon on your home screen, click on it and you will see a splash screen and then the default page.

Progressive Web App

Progressive Web App

Progressive Web App

Notice, there are no browser UI at the top and our application looks responsive as well.

You can download the full demo from here.

I hope you like it.