© Carlos Rojas 2020
C. RojasBuilding Progressive Web Applications with Vue.js https://doi.org/10.1007/978-1-4842-5334-2_2

2. Web App Manifest

Carlos Rojas1 
(1)
Medellin, Colombia
 

The manifest file is a way to tell web browsers, and especially mobile devices, how to show your app. It is basically a JSON file in which you specify many properties along with their values.

Creating Our Manifest

In Chapter 1, we created the manifest file with a generator. In this chapter, we create it from scratch to acquire an understanding of its properties.

To begin, we create a file in the root at the same level of the main entry (usually index.html) with the name manifest.json and add
{}

Our file is now ready, but we need to add some properties so that web and mobile browsers understand which properties to use when installing our app.

name

name provides a name for the site when displayed to the user.
"name": "VueNoteApp",

short_name

short_name provides a short name for the application. This property is similar to name, but is used when there is insufficient space to display the full name of the PWA.
"short_name": "VueNoteApp",

theme_color

theme_color defines the default theme color for an application.
"theme_color": "#36495d",

background_color

background_color defines the expected background color for the web site.
"background_color": "#36495d",

description

description provides a general description of what the pinned web site does.
"description": "Our first Progressive Web App using VueJS",

display

display defines the developers’ preferred display mode for the web site.
"display": "standalone",

You can use also fullscreen, minimal-ui, and browser. For more information, go to https://developer.mozilla.org/en-US/docs/Web/Manifest#display. With standalone, we can show our app as a regular native app with an icon.

orientation

orientation defines the default orientation for the web site’s top-level browsing contexts.
"orientation": "portrait",

You can find more orientation values at https://developer.mozilla.org/en-US/docs/Web/Manifest/orientation. With portrait, we can show our app as apps are usually seen in mobile devices.

scope

scope restricts the web pages that can be viewed. If, while you are in your app, you navigate to an app that is out of scope, a regular browser window is opened. For example, if, in my app, I have /app and /assets from the root folder and I choose "scope": "/app" and try to call /assets/logo.png, this opens a new tab in the web browser because it is out of the context of my app.
"scope": "/app",

start_url

start_url specifies the main entry point (usually index.html) when you add to the home screen.
"start_url": "/",

icons

icons specifies an array of image files that can serve as application icons, depending on context.
"icons": [
{
        "src": "./icons/icon-72x72.png",
        "sizes": "72x72",
        "type": "image/png"
},
{
        "src": "./icons/icon-96x96.png",
        "sizes": "96x96",
        "type": "image/png"
},
{
        "src": "./icons/icon-128x128.png",
        "sizes": "128x128",
        "type": "image/png"
},
{
        "src": "./icons/icon-144x144.png",
        "sizes": "144x144",
        "type": "image/png"
},
{
        "src": "./icons/icon-152x152.png",
        "sizes": "152x152",
        "type": "image/png"
},
{
        "src": "./icons/icon-192x192.png",
        "sizes": "192x192",
        "type": "image/png"
},
{
        "src": "./icons/icon-384x384.png",
        "sizes": "384x384",
        "type": "image/png"
},
{
        "src": "./icons/icon-512x512.png",
        "sizes": "512x512",
        "type": "image/png"
}
],

The Final Manifest

Putting all the parts together, we have a manifest.json file with properties and values for VueNoteApp.
{
       "name": "VueNoteApp",
       "short_name": "VueNoteApp",
       "theme_color": "#36495d",
       "background_color": "#36495d",
       "display": "standalone",
       "orientation": "portrait",
       "scope": "/",
       "start_url": "/",
       "icons": [
       {
               "src": "./icons/icon-72x72.png",
               "sizes": "72x72",
               "type": "image/png"
       },
       {
               "src": "./icons/icon-96x96.png",
               "sizes": "96x96",
               "type": "image/png"
       },
       {
               "src": "./icons/icon-128x128.png",
               "sizes": "128x128",
               "type": "image/png"
       },
       {
               "src": "./icons/icon-144x144.png",
               "sizes": "144x144",
               "type": "image/png"
       },
       {
               "src": "./icons/icon-152x152.png",
               "sizes": "152x152",
               "type": "image/png"
       },
       {
               "src": "./icons/icon-192x192.png",
               "sizes": "192x192",
               "type": "image/png"
       },
       {
               "src": "./icons/icon-384x384.png",
               "sizes": "384x384",
               "type": "image/png"
       },
       {
               "src": "./icons/icon-512x512.png",
               "sizes": "512x512",
               "type": "image/png"
       }
       ]
}

Linking Our Manifest in Our App

Adding the manifest to our app is easy. We just link it in the main entry (usually index.html):
<link rel="manifest" href="/manifest.json">
You can go there from the repo (https://github.com/carlosrojaso/appress-book-pwa) with
$git checkout v1.0.5

Debugging Our Web App Manifest

To see if everything works fine, we need to open Chrome DevTools and locate the Application tab (Figure 2-1).
../images/483082_1_En_2_Chapter/483082_1_En_2_Fig1_HTML.jpg
Figure 2-1

Google Chrome DevTools Application tab

From it, we select Manifest (Figure 2-2).
../images/483082_1_En_2_Chapter/483082_1_En_2_Fig2_HTML.jpg
Figure 2-2

Google Chrome DevTools manifest properties view. In this tab you can see how the web browser is understanding your properties in the web app manifest

Summary

The web app manifest is a JSON file that tells web browsers, and especially mobile devices, how to show your app. It delineates the name, icons, and background color, among other things.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.70.157