Progressive Web App (PWA) Manifest File in Blazor

This article is going to explain what a manifest file is and how to use it in the PWA Blazor application. You can easily configure the manifest in your Blazor app. Let's see how to do it.

What is a Manifest File?

Manifest is a single JSON file that tells the browser what kind of application it is, What is the name of the application? Where is the application icon? What background color and etc. The manifest file name must be manifest.json

While creating the Blazor application, it will automatically create the manifest.json file under wwwroot folder.

The following is a default manifest.json code.

{
  "name": "SamplePWABlazorApp",
  "short_name": "SamplePWABlazorApp",
  "start_url": "./",
  "display": "standalone",
  "background_color": "#ffffff",
  "theme_color": "#03173d",
  "icons": [
    {
      "src": "icon-512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ]
}

name: The name of the application. This will be displayed in the title bar of the application, under the icon and in the Start menu.

short_name: This short name will appear under the app icon. But it only appears when the name is too long to display.

start_url: This allows you to set the page to be opened when the user clicks on the icon. “./” will open an index page.

display: It helps to set the display mode of the application.

  • "display": "standalone" - This will make your application look like a native application
  • "display": "browser" - This will open the application in the browser.
  • "display": "fullscreen" - This will open the web application without any browser and take up the entire display area available.
  • "display": "minimal-ui" - It gives the same look as the standalone, but it does have navigation controls.

background_color: This helps to set the background color of the application

theme_color: It helps to set the theme color of the application. I have changed the default theme color #03173d to #03c740 (green) to illustrate the theme color. You can see the title theme color changes to green in the following screeningshot

icons: The icon is an array of objects that represent different sizes of an icon. The application will use the icon based on the device you are using. The following code snippets explain how to add multiple icons.

  "icons": [
    {
      "src": "/images/icons-192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "/images/icons-512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ]

There are three properties.
  • src - Image source
  • type - Type of the image
  • size - Size of the image

In the browser, you can check the details of your application manifest file. The following is a Chrome browser devTools screenshot. Right-click -> Inspect -> Application -> Manifest (left hand side)

Let us now see how the manifest file is included in the Blazor application. Under wwroot folder you can find index.html, in the file inside the header tag, you can find the link to the manifest.json file.

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>SamplePWABlazorApp</title>
    <base href="/" />
    <link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link href="css/app.css" rel="stylesheet" />
    <link href="manifest.json" rel="manifest" />
    <link rel="apple-touch-icon" sizes="512x512" href="icon-512.png" />
</head>

I hope this helps you. Keep coding.

Comments

Popular posts from this blog

Entity Framework Core (EF) with SQL Server LocalDB

Creating a C# Azure Function with Visual Studio: Step-by-Step Guide

Exploring EventCallback in Blazor: Building Interactive Components