Dev.to WebDev 🛠 Dev 👁 0 📖 6 min read

Fourteen image routes, seven link preview cards, and 93 per cent of the pixels are the same picture

PubTrivia draws its link preview cards in code rather than exporting them from a design tool: a React component rasterised by Satori through next/og, reading the same logo file and the same palette the site uses. I have

PubTrivia draws its link preview cards in code rather than exporting them from a design tool: a React component rasterised by Satori through next/og, reading the same logo file and the same palette the site uses. I have written about why that is a good idea. This post is about what the 14 routes actually produce, measured by fetching every one of them and decoding the pixels.

There are 111 URLs in the sitemap and 7 distinct card images between them.

The routes

app/opengraph-image.tsx                 app/twitter-image.tsx
app/compare/opengraph-image.tsx         app/compare/twitter-image.tsx
app/features/opengraph-image.tsx        app/features/twitter-image.tsx
app/guides/opengraph-image.tsx          app/guides/twitter-image.tsx
app/quiz-questions/opengraph-image.tsx  app/quiz-questions/twitter-image.tsx
app/solutions/opengraph-image.tsx       app/solutions/twitter-image.tsx
app/tools/opengraph-image.tsx           app/tools/twitter-image.tsx

Seven pairs. Each twitter-image.tsx imports the default export of the opengraph-image.tsx beside it and re-exports it, because X reads twitter:image and only some clients fall back to og:image. The file exists to give Next a second metadata route, not a second design, and the comment in it says exactly that.

Fetching all 14 and hashing the bytes confirms it. Seven distinct SHA-256 values, each shared by exactly one opengraph-image and one twitter-image:

route                              bytes    sha256 (first 12)
---------------------------------  -------  -----------------
/opengraph-image                    91,693  ab913f9da4db
/twitter-image                      91,693  ab913f9da4db
/quiz-questions/opengraph-image     83,051  0c1ec89eaecb
/solutions/opengraph-image          82,555  0153e1562314
/features/opengraph-image           80,455  4b0b0b82dd3d
/tools/opengraph-image              77,956  1d5138d40fcc
/compare/opengraph-image            77,425  2007fdd13253
/guides/opengraph-image             72,783  7205695022b4

565,918 bytes of distinct image for 111 pages, and 1.13 MB of CDN objects because each one exists under two URLs.

The pixels

I decoded all seven PNGs in Node (zlib plus the five filter types, about 25 lines) rather than trusting any image library, and counted.

card             bytes    distinct   #171717    identical to
                          colours    share      the root card
---------------  -------  --------   --------   -------------
root              91,693     2,495     70.1%        -
quiz-questions    83,051     2,147     70.4%       90.92%
solutions         82,555     2,134     70.0%       90.54%
features          80,455     2,080     70.4%       90.88%
tools             77,956     2,085     70.5%       90.95%
compare           77,425     1,918     71.0%       93.07%
guides            72,783     1,875     71.2%       93.24%

Every card is 1200 x 630. Every card is 8-bit RGBA, and in every card all 756,000 pixels are fully opaque, so the alpha channel is 756,000 bytes of 0xff before compression and exactly nothing after it.

The last column is the interesting one. Between 90.5 and 93.2 per cent of each card's pixels are identical to the root card's, pixel for pixel. The background colour, the 40-pixel grid, the amber bloom behind the mug, the wordmark lockup, the footer rule, the domain and the pill that says "No app. No accounts." are all in the same place in all seven. What differs is the eyebrow, the heading and one line of blurb: around 7 per cent of the image, which is the design working as intended rather than a problem, but it does mean 7 PNGs are carrying one picture plus three strings.

Between 1,875 and 2,495 distinct colours per card, out of four flat colours in the design. The rest is anti-aliasing on the text, which is also why the card with the longest subheading is the largest file.

290 KB of font to draw 105 glyphs

Every render reads four TrueType files off disk, because Satori does not accept the WOFF2 that next/font downloads:

Geist-Regular.ttf        72,916
Geist-SemiBold.ttf       73,048
Geist-Bold.ttf           72,984
GeistMono-Regular.ttf    71,160
                        -------
                        290,108 bytes per render

Counting the distinct characters each face has to draw, across all seven cards together:

face                 distinct glyphs needed
-------------------  ----------------------
Geist Bold               33  (the headings)
Geist Regular            36  (the blurbs)
Geist SemiBold           26  (eyebrow, wordmark, pill)
Geist Mono               10  (pub-trivia.app)

105 glyphs, and the 71,160-byte mono face is read, parsed and discarded to draw ten of them: p u b - t r i v a . in the footer line. A subsetted copy of each face would be a few kilobytes.

There is a second reason that mono file is interesting. A measurement two weeks ago found that the site's own CSS never applies Geist at all: a variable in the Tailwind theme block uses the wrong namespace, so every public page renders in the system sans-serif while two WOFF2 files download anyway. The link preview card is therefore the one surface on the whole property where the brand typeface actually appears. The card and the page you land on are set in different fonts, and the card is the correct one.

force-static, and what the headers say

All 14 route files declare the same thing, with a comment explaining why:

export const dynamic = "force-static"

The reasoning is sound: the renderer reads the logo and the fonts off disk, those files live on the build machine, and a crawler asking for a preview should get a PNG off the CDN rather than wait on a cold function.

The live responses are not quite that. Fetching all 14 cold, seven came back like this:

age: 0
cache-control: public, max-age=0, must-revalidate
x-vercel-cache: REVALIDATED
x-vercel-id: fra1::iad1::pw92p-1794999675856-5034a3707808
(no etag, no accept-ranges)

Three fields in x-vercel-id means the request did not stop at the edge in Frankfurt: it went on to the function region in Virginia, which is where iad1 is. No ETag, because there was nothing stored to compute one against yet. A minute later the same URL answers:

age: 50
cache-control: public, max-age=0, must-revalidate
etag: "4dfd39cb8b313328b3564de139e16db8"
accept-ranges: bytes
content-disposition: inline
access-control-allow-origin: *
vary: rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch
x-vercel-cache: HIT
x-vercel-id: fra1::mrbbc-1794999727059-4a09fca58d84

Two fields, served from Frankfurt, 88 to 124 ms warm over six measurements. Some cards in my sweep had an age of 84,502 seconds, so an object can sit at the edge for a day. But none of the 14 carried the prerender marker that the site's 109 static HTML pages all carry, and the cold ones were answered by the function. So whatever force-static did at build time, the thing on the CDN is not an immutable asset: it is an ISR object with max-age=0, must-revalidate that is re-rastered when the edge has nothing.

Also, and I enjoyed this more than I should have: a PNG is being served with vary on four React Server Component routing headers. An image does not vary on next-router-prefetch, and the four values are there because the whole app's responses carry them.

One thing I could not measure. Adding a query string does not create a new cache key for these routes (three different ?cb= values all answered HIT with a rising age), so I could not force a cold render on demand and have no honest cold TTFB to report. The REVALIDATED responses above are the evidence that renders happen; how long one takes is not something this measurement can tell you.

The tag asymmetry, which is already known

While I had all 111 pages on disk I checked which card each page points at:

card                           pages naming it as twitter:image
-----------------------------  -------------------------------
/quiz-questions/twitter-image                36
/guides/twitter-image                        26
/solutions/twitter-image                     14
/compare/twitter-image                       11
/features/twitter-image                      10
/tools/twitter-image                          7
/twitter-image                                7
                                            ---
                                            111

And og:image, on 7 pages: the six cluster hubs and the homepage. That is not a new finding. It is the Next.js metadata merge behaviour where a page's openGraph object replaces the root layout's instead of merging into it, so a page that sets openGraph.title loses the inherited openGraph.images, while the separately declared twitter.images survives. It has been written up twice on this account already, and I am repeating the count here only because the number of affected pages has grown from 72 to 111 since.

What I would change

  1. Set openGraph.images where each page's own openGraph object is built, which fixes 104 pages' Facebook, LinkedIn and WhatsApp previews.
  2. Subset the four TTFs to the glyphs the cards actually use. 105 across all seven cards, against 290,108 bytes read per render.
  3. Drop the alpha channel. Every pixel is opaque; nothing needs RGBA.
  4. Work out whether these can be genuine build assets rather than ISR objects, or accept that they are ISR objects and stop telling the next reader they are prerendered.

If you want to look at them, they are public and need no account: the site card, the same card under its other name, and the cluster cards at /features/opengraph-image, /guides/opengraph-image and /tools/opengraph-image. Save any two and compare the bytes.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.