manifest.ts
Generate the web app manifest from code: app/manifest.ts returns the manifest object and GioJS serves it at /manifest.webmanifest.
app/manifest.ts
import type { MetadataRoute } from '@gio.js/core';
export default function manifest(): MetadataRoute.Manifest {
return {
name: 'Acme Store',
short_name: 'Acme',
start_url: '/',
display: 'standalone',
background_color: '#ffffff',
theme_color: '#0f172a',
icons: [
{ src: '/icons/icon-192.png', sizes: '192x192', type: 'image/png' },
{ src: '/icons/icon-512.png', sizes: '512x512', type: 'image/png' },
],
};
}Reference
File name and location
app/manifest.ts or app/manifest.js, at the root of app/ only. It answers /manifest.webmanifest.
Exports
| Field | Type | Default | Description |
|---|---|---|---|
default (required) | Manifest | (() => Manifest | Promise<Manifest>) | - | A Web App Manifest object, or a function returning one. Manifest is Record<string, unknown>: any member the specification defines may be used. |
revalidate | number | false | 3600 | Seconds the output is cached. false keeps it until the next deploy, 0 generates it on every request. |
Response
200,Content-Type: application/manifest+json; charset=utf-8, the object as JSON (indented by two spaces).- Only
GETandHEAD: other methods get405withAllow: GET, HEAD. - Cached by the server for
revalidateseconds, with anETagand no automaticCache-Control. - A result that is not a plain object (an array,
null), or a function that throws, answers500Internal Server Error (ref <digest>).
Examples
Link the manifest from every page
Browsers find the manifest through a <link rel="manifest">, which GioJS does not add by itself. Set it once in the root layout's metadata:
app/layout.tsx
import React from 'react';
import type { LayoutProps, Metadata } from '@gio.js/core';
export const metadata: Metadata = {
title: { default: 'Acme Store', template: '%s | Acme Store' },
manifest: '/manifest.webmanifest',
};
export default function RootLayout({ children }: LayoutProps) {
return (
<html lang="en">
<head />
<body>{children}</body>
</html>
);
}Every page then carries <link rel="manifest" href="/manifest.webmanifest">.
Good to know
- GioJS does not check the manifest's members and does not resolve URLs in it: write
start_urland iconsrcvalues as the browser should read them. Icons are ordinary files inpublic/. - A
public/manifest.webmanifestwins overapp/manifest.ts, with a startup warning. A page orroute.tsat that URL stops startup. A staticpublic/manifest.jsonis a different URL and does not conflict. gio exportwritesout/manifest.webmanifestfrom it.- There are no file-based icons (
app/icon.png,app/apple-icon.png): use theiconsmetadata field.
Related
- Metadata & SEO - the guide.
- sitemap.ts, robots.ts,
metadata
Version history
| Version | Changes |
|---|---|
v0.1.0-beta.8 | Introduced: app/manifest.ts serves /manifest.webmanifest, on the server, in standalone builds and in gio export. |