That's how I understand it
site.webmanifest
is basically a JSON file, which is used by Android devices (Apple uses apple-touch-icon
) to look for some parameters (favicon, theme color, long and short name of your application) in order to display your application properly on your mobile or tablet device. This JSON file should have the format compatible with PWA.
For example, you would like to add some website to the home screen on your device and use it as a regular (pre-installed, native) app. If the website doesn't have webmanifest file, your device would not be able to determine website icon, so it will have to display that ugly default one. That's bad for user experience.
A simplified example of site.webmanifest
would look like this:
{
"name": "<your app name>",
"icons": [
{ "src": "/android-chrome-192x192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "/android-chrome-512x512.png", "sizes": "512x512", "type": "image/png" }
]
}
Andrey Sitnik has a great article about favicon and webmanifest, if you want to go deeper.
So,
Is it a mandatory file in the development of web pages?
No, your web app will be working fine without it. But it's highly recommended for improving user experience on every device.
When and why it is used?
It lets your web app to be used as PWA and improve user experience.
How do I know when I have to use it?
If your app is used by certain category of people and you are 100% sure they dont't need (and don't want) to use PWA features, you probably shouldn't care about it. For example, if you are building a corporate B2B admin dashboard or portal, you most likely don't need PWA. But if you are building an app that can be used by anyone in the Internet (e.g. Trello, Notion, GitHub), you should care about it.