Show contents
Chapter 2 of 7 · 20 min
The manifest and installation
By the end of this chapter, you'll be able to
- Explain what a progressive web app is and what it requires
- Write a web app manifest
- Automatically check that a manifest is complete
- Compare a PWA with a native app
What a PWA is
A progressive web app is a website that adds three ingredients:
- it is served over HTTPS, required for the advanced features;
- it provides a manifest: a JSON file describing the app (name, icons, colours, display mode);
- it registers a service worker: a script that can intercept network requests and serve cached files, and so work offline. You will write it in the next chapter.
“Progressive” means it improves according to what the device allows: on an old browser, it is a normal website; on a recent browser, it becomes installable and works offline.
The manifest
The manifest is a file, often manifest.webmanifest, declared in the <head> of every page:
<link rel="manifest" href="/manifest.webmanifest">
{
"name": "Cooperative market prices",
"short_name": "Market prices",
"start_url": "/?source=pwa",
"scope": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#1f6f43",
"icons": [
{ "src": "/icons/192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "/icons/512.png", "sizes": "512x512", "type": "image/png" },
{ "src": "/icons/maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
]
}
nameis shown at installation,short_nameunder the icon on the home screen;start_urlis the page opened at launch, andscopethe set of addresses that belong to the app;display: "standalone"opens the app without the browser's address bar;- the 192 and 512 pixel icons are used for the home screen and the splash screen; a
maskableicon can be cut into a circle or a rounded square depending on the phone.
Launched from the icon, the app opens without an address bar, even without a network.
Text description of the animation
- The member opens the site in their browser, like any other site.
- The browser reads the manifest: it knows how to present the app.
- The script caches the essential files for the next visits.
- The browser offers installation; the icon joins the other apps'.
- Launched from the icon, the app opens without an address bar, even without a network.
Checking a manifest
An incomplete manifest prevents installation, often with no visible error message. Let's check it with a little JavaScript:
function check(manifest) {
const problems = [];
for (const field of ["name", "short_name", "start_url", "display", "icons"]) {
if (!(field in manifest)) problems.push(`missing field: ${field}`);
}
const sizes = (manifest.icons ?? []).map((i) => i.sizes);
for (const size of ["192x192", "512x512"]) {
if (!sizes.includes(size)) problems.push(`missing ${size} icon`);
}
if (manifest.short_name && manifest.short_name.length > 12) {
problems.push(`short_name too long (${manifest.short_name.length} characters), it may be cut off`);
}
return problems.length ? problems : ["complete manifest"];
}
console.log(check({
name: "Cooperative market prices",
short_name: "Coop market prices",
start_url: "/",
icons: [{ src: "/icons/192.png", sizes: "192x192" }],
}));
["missing field: display","missing 512x512 icon","short_name too long (18 characters), it may be cut off"]
The 12-character limit for short_name is a common recommendation, not a strict rule: beyond it, the name may be truncated under the icon. Browsers' developer tools (the “Application” or “Manifest” tab) run a similar, more complete check.
PWA or native app?
A PWA is a very good fit for a content, commerce or forms app: a single codebase, no mandatory app store, instant updates, and a much lighter footprint, precious on phones short of space. A native app (written for Android or iOS, or with a cross-platform tool such as Flutter or React Native) remains preferable when you need advanced device features, high graphics performance, or a presence in the stores. Support for PWA features also varies between browsers and systems: always check on your audience's devices.
Mini-lab: fix this manifestJavaScript
Output
Click “Run” to execute your code.Your code runs in your browser, isolated from the page. · Ctrl/⌘ + Enter to run · Esc then Tab to leave the editor
Your turn
Worked exercise
Worked exercise: the right icon for each use
Write a function bestIcon(icons, wantedSize) that returns the icon whose size is closest to wantedSize without being smaller (an enlarged icon becomes blurry). If none is big enough, it returns the largest available.
const icons = [
{ src: "/i/96.png", sizes: "96x96" },
{ src: "/i/192.png", sizes: "192x192" },
{ src: "/i/512.png", sizes: "512x512" },
];
Hint 1
parseInt("192x192") gives 192: parseInt stops at the first character that is not a digit.Hint 2
find.Show the solution and common mistakes
const icons = [
{ src: "/i/96.png", sizes: "96x96" },
{ src: "/i/192.png", sizes: "192x192" },
{ src: "/i/512.png", sizes: "512x512" },
];
function bestIcon(list, wantedSize) {
const sorted = [...list].sort((a, b) => parseInt(a.sizes) - parseInt(b.sizes));
return sorted.find((i) => parseInt(i.sizes) >= wantedSize) ?? sorted.at(-1);
}
for (const size of [48, 144, 192, 1024]) {
console.log(`${size} px → ${bestIcon(icons, size).src}`);
}
48 px → /i/96.png
144 px → /i/192.png
192 px → /i/192.png
1024 px → /i/512.png
This is the browser's reasoning: it happily shrinks a large icon, but enlarging a small one gives a blurry result. Hence the value of always providing at least a 512-pixel icon.
Common mistakes:
- Sorting
iconsdirectly withsort: the original list is modified. The[...list]copy avoids that. - Comparing sizes as strings:
"96x96" > "512x512"is true, because"9"comes after"5".
Summary
- 1A PWA is a website over HTTPS, with a manifest and a service worker.
- 2The manifest describes the name, start page, scope, display mode and icons.
- 3192 and 512 pixel icons (including a maskable one) are expected for installation.
- 4The start_url must be inside the scope, otherwise the app does not cover the planned pages.
- 5A PWA fits most content apps; native remains useful for advanced needs.
Your progress is saved on this device. Create a free account to keep your progress on all your devices.