Part 04 / Topic 7 of 8
Favicons and Open Graph images: file conventions, not configuration
harness/app/favicon.ico has existed since Part 1's first scaffold, toured but never explained. The installed package's own guide names the mechanism directly: "create a favicon.ico and add to the root of the app folder" — no export, no config, just a file at a conventional name and path:
$ curl -s -D - -o /dev/null http://localhost:PORT/favicon.ico | grep -iE "^(HTTP|content-type)"
HTTP/1.1 200 OK
Content-Type: image/x-icon
Open Graph images work the same way, through a different filename. app/store/opengraph-image.tsx generates one, scoped to every page under /store, using ImageResponse from next/og:
import { ImageResponse } from "next/og";
export const alt = "Apna Bazaar";
export const size = { width: 1200, height: 630 };
export const contentType = "image/png";
export default function OgImage() {
return new ImageResponse(
<div style={{ width: "100%", height: "100%", display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", background: "#1f5c8c", color: "white", fontSize: 96 }}>
Apna Bazaar
<div style={{ fontSize: 32, marginTop: 16 }}>Handmade goods from Jaipur, Varanasi and Chennai</div>
</div>,
size,
);
}
Next.js wires every one of these fields into real <head> tags automatically, confirmed on a storefront page:
$ curl -s http://localhost:PORT/store/about | grep -o '<meta property="og:[a-z:]*" content="[^"]*"'
<meta property="og:title" content="About | Apna Bazaar"
<meta property="og:description" content="How Apna Bazaar started, and where its handmade goods ship from."
<meta property="og:image" content="http://localhost:PORT/store/opengraph-image?f9bc1875e9d3494b"
<meta property="og:image:type" content="image/png"
<meta property="og:image:width" content="1200"
<meta property="og:image:height" content="630"
<meta property="og:image:alt" content="Apna Bazaar"
$ curl -s -o og.png -D - http://localhost:PORT/store/opengraph-image | grep -i content-type
content-type: image/png
$ file og.png
og.png: PNG image data, 1200 x 630, 8-bit/color RGBA, non-interlaced
og:title and og:description reused /store/about's own static metadata (section 1) automatically — nothing in opengraph-image.tsx mentions title or description at all, only the image itself. The root page, /, has no og: tags whatsoever, because no opengraph-image file exists at app/'s root and no openGraph field was set on the root's metadata — this file convention, like every other one this course has met, only applies where the file actually exists.
One environment-dependent detail, caught by testing both next dev and a real next build && next start rather than only one: the og:image URL above resolved against http://localhost:PORT under next dev, but against metadataBase — https://nextjs-step-by-step.test/store/opengraph-image?... — once the exact same code ran under a production next start. next dev falls back to the actual request's own origin when resolving a relative metadata URL; a production build always prefers the explicit metadataBase set in section 1. Testing only next dev here would have reported the wrong URL for what actually ships.
Full file: examples/07-store-opengraph-image.tsx.
Done here? The practice set for Part 4 — including the solutions — is on the part page.