Skip to content

perf(docsite): load blog cover images through the image optimizer - #12536

Merged
nynexman4464 merged 1 commit into
mainfrom
nynexman4464/perf/docsite-blog-cover-images
Nov 19, 2026
Merged

nynexman4464 merged 1 commit into
mainfrom
nynexman4464/perf/docsite-blog-cover-images

Conversation

@nynexman4464

@nynexman4464 nynexman4464 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Primary intent

Load each blog cover image through the Next.js image optimizer. This is a docsite performance change: it restores no broken behavior, adds no capability, and changes no appearance, so no other template fits.

User or maintainer impact

Anyone who opens the blog index, a post, or the landing page. Today each cover loads as the file its post names: PNG and JPEG files up to 3840 pixels wide, and one GIF. A cover is 342 to 824 CSS pixels wide at the measured viewports (390 and 1440 px), and up to 975 between them.

Page Cover bytes before Cover bytes after
/blog (10 covers) 4,706 KiB 668 KiB
A post page (astryx-cli-build-command) 1,370 KiB 153 KiB
/ (3 covers in "Stay in the know") 623 KiB 121 KiB

Post authors change nothing: a cover stays a full-size file under public. One difference for them: the optimizer keeps its own copy of a cover, for 4 hours by default (minimumCacheTTL), and the deployments of the project share that copy. A cover file replaced under the same name can then show the old picture for up to about 4 hours. On the deployed preview the optimizer's answer carries max-age=0, must-revalidate, so a browser checks again on each load. Today the file is checked again on each load. The theme showcase photos behave the same way.

Problem and solution fit

  • Why are the pages heavy? BlogCard, BlogFeatureCard, and BlogArticle render <img src={post.coverImage}>, the full-size file.
  • Why does that hurt? The blog index downloads 4,706 KiB of covers to show ten pictures that are 342 to 752 CSS pixels wide.
  • Why does it matter? On a 10 Mbps link, a post's cover is the largest paint, and it arrives after about 4.0 s. It now arrives after about 0.7 s.

Each delta maps to that problem:

Delta Why it is needed
src/lib/blog/coverImage.ts blogCoverUrl(coverImage) returns the optimizer URL from the existing optimizedImageUrl helper for a root-relative PNG or JPEG path. Any other cover keeps its own URL.
BlogCard, BlogFeatureCard, BlogArticle Each <img> loads blogCoverUrl(post.coverImage). Nothing else in the markup changes.
src/lib/optimizedImageUrl.mjs, scripts/template-image-loader.mjs The rule for which formats the optimizer converts (PNG and JPEG) moves from the template image loader to the shared helper as isOptimizedFormat. The loader and the covers then use one rule. The loader's output does not change.
src/content/blog/README.md Tells a post author that the site resizes a PNG or JPEG cover, and that any other format loads as it is.
Tests The URL each render site produces, the covers that keep their own URL, and the metadata that must not change.

No tagalong changes, and no public API change: nothing under packages/ is touched.

One width, 1920 pixels

The width comes from the widest layout of each place that shows a cover, at two device pixels per CSS pixel. Of the widths the optimizer allows, those of 640 and up are 640, 750, 828, 1080, 1200, 1920, 2048, and 3840.

Place Widest cover Viewport where it is widest Pixels on a 2x screen Smallest allowed width that covers it
Article cover, index feature card 752 CSS px 800 px and wider 1,504 1920
Landing feature card, two columns 824 CSS px 1248 px and wider 1,648 1920
Index grid card, one column 659 CSS px 707 px 1,318 1920
Landing cards, one column (the feature card too) 975 CSS px 1023 px 1,950 2048

1920 covers every layout at 2x except one: the one-column landing cards on a viewport of 1009 to 1023 px, where it gives 1.97 to 2.00 image pixels per CSS pixel. 2048 would make every cover larger for that band of 15 px.

A smaller width for the index grid is the one saving on offer, and it was measured:

Option /blog cover bytes Cost
1920 for every cover (this change) 668 KiB None. A card and its article share one download, and so do the index and the landing page.
1080 for index grid cards 510 KiB A width prop on BlogCard. The router's prefetch of the landing page downloads two covers a second time at 1920 (117 of the 510 KiB). A one-column grid card on a 2x screen gets 1.6 image pixels per CSS pixel.
srcset and sizes 208 to 388 KiB, by screen A sizes value for each of the five layouts, kept in step with their CSS breakpoints.

The optimizer returns a file no wider than its source, so a 1200-pixel cover stays 1200 pixels wide, as it is today.

Covers that keep their own URL

  • An animated GIF. /blog/the-astryx-cli/cover.gif is the one GIF cover. The optimizer returns it byte for byte (151,605 bytes, image/gif, 11 frames, on the production site, the deployed preview, and a local build), so the request would add a step and save nothing.
  • Any other format that is not PNG or JPEG. The shared rule names the two formats the docsite's photos use. The optimizer refuses an SVG.
  • A URL on another host, and a path with a query string. The optimizer answers 400 for each of them on the local build, and for a query string on the deployed preview.

Left as it is

  • Page metadata. og:image and twitter:image keep the cover file's own URL, because a crawler needs the file itself. A test pins this for a post with a cover.
  • The feed, the sitemap, and the plain-text post route. They name no cover.
  • Images in a post's body. Out of scope. The largest are one-month-of-astryx/community-showcase.png (2,623 KiB) and astryx-meetup-are-design-systems-still-valuable/photo-07.jpg (814 KiB).
  • Lazy loading. No cover gets loading="lazy". The article cover and the index feature card are the largest paint on their pages.

Authority

spec:AST-033 and architecture:knowledge-contracts are linked to apps/docsite/**. None of their claims covers the URL an image loads from, and pnpm specs:for --diff origin/main routes no concern claim to the added lines. The change follows the path that the template previews (#11320) and the theme showcase photos (#11369) use, through the same optimizedImageUrl helper.

Change and evidence

Status of the evidence:

  • Measured on local production builds (next build, then next start) of main and of this branch: the bytes, requests, largest paint, and screenshots, in Chromium 149 with a cold browser cache. The branch build is from a commit before the last one, which changed comments and tests only.
  • Measured on the deployed preview of this head against the deployed main: the bytes, requests, largest paint, the GIF, and the cache header. See "Deployed preview".

"Covers" counts requests for a post's cover file, direct or through the optimizer.

Page Viewport Images before Images after Covers before Covers after
/blog 1440 px, scale 1 39 requests, 5,009 KiB 39 requests, 971 KiB 10 requests, 4,706 KiB 10 requests, 668 KiB
/blog 1440 px, scale 2 39 requests, 5,009 KiB 39 requests, 971 KiB 10 requests, 4,706 KiB 10 requests, 668 KiB
/blog 390 px, scale 1 39 requests, 5,009 KiB 39 requests, 971 KiB 10 requests, 4,706 KiB 10 requests, 668 KiB
/blog 390 px, scale 2 39 requests, 5,009 KiB 39 requests, 971 KiB 10 requests, 4,706 KiB 10 requests, 668 KiB
Post page 1440 px, scale 1 18 requests, 1,709 KiB 18 requests, 493 KiB 2 requests, 1,518 KiB 2 requests, 301 KiB
Post page 1440 px, scale 2 18 requests, 1,709 KiB 18 requests, 493 KiB 2 requests, 1,518 KiB 2 requests, 301 KiB
Post page 390 px, scale 1 18 requests, 1,709 KiB 18 requests, 493 KiB 2 requests, 1,518 KiB 2 requests, 301 KiB
Post page 390 px, scale 2 18 requests, 1,709 KiB 18 requests, 493 KiB 2 requests, 1,518 KiB 2 requests, 301 KiB
/ 1440 px, scale 1 71 requests, 1,771 KiB 71 requests, 1,269 KiB 3 requests, 623 KiB 3 requests, 121 KiB
/ 1440 px, scale 2 70 requests, 1,772 KiB 70 requests, 1,269 KiB 3 requests, 623 KiB 3 requests, 121 KiB
/ 390 px, scale 1 71 requests, 1,771 KiB 71 requests, 1,269 KiB 3 requests, 623 KiB 3 requests, 121 KiB
/ 390 px, scale 2 70 requests, 1,771 KiB 70 requests, 1,269 KiB 3 requests, 623 KiB 3 requests, 121 KiB

The cover columns are the same in every row of a page, because one URL serves each cover. On /, one image outside the covers differs by scale. The post page is /blog/astryx-cli-build-command. Its second cover request is the GIF cover of a post that it links to. The router's prefetch of that post downloads it: 148 KiB before and after.

Deployed preview

The preview of this head (astryx-git-nynexman4464-perfdocsite-blog-co-faee17-fbopensource.vercel.app) against the deployed main (astryx-git-main-fbopensource.vercel.app), with the same browser and method.

Page Viewport Images before Images after Covers before Covers after
/blog 1440 px, scale 1 48 requests, 6,509 KiB 48 requests, 2,467 KiB 10 requests, 4,708 KiB 10 requests, 666 KiB
/blog 1440 px, scale 2 48 requests, 6,509 KiB 48 requests, 2,467 KiB 10 requests, 4,708 KiB 10 requests, 666 KiB
/blog 390 px, scale 1 48 requests, 6,509 KiB 48 requests, 2,467 KiB 10 requests, 4,708 KiB 10 requests, 666 KiB
/blog 390 px, scale 2 48 requests, 6,509 KiB 48 requests, 2,467 KiB 10 requests, 4,708 KiB 10 requests, 666 KiB
Post page 1440 px, scale 1 32 requests, 2,974 KiB 30 requests, 1,250 KiB 5 requests, 2,141 KiB 5 requests, 422 KiB
Post page 1440 px, scale 2 32 requests, 2,974 KiB 30 requests, 1,250 KiB 5 requests, 2,141 KiB 5 requests, 422 KiB
Post page 390 px, scale 1 32 requests, 2,974 KiB 30 requests, 1,250 KiB 5 requests, 2,141 KiB 5 requests, 422 KiB
Post page 390 px, scale 2 32 requests, 2,974 KiB 30 requests, 1,250 KiB 5 requests, 2,141 KiB 5 requests, 422 KiB
/ 1440 px, scale 1 77 requests, 3,162 KiB 75 requests, 2,654 KiB 3 requests, 623 KiB 3 requests, 120 KiB
/ 1440 px, scale 2 78 requests, 3,162 KiB 76 requests, 2,654 KiB 3 requests, 623 KiB 3 requests, 120 KiB
/ 390 px, scale 1 78 requests, 3,162 KiB 76 requests, 2,654 KiB 3 requests, 623 KiB 3 requests, 120 KiB
/ 390 px, scale 2 78 requests, 3,162 KiB 76 requests, 2,654 KiB 3 requests, 623 KiB 3 requests, 120 KiB
  • The deployed pages load more images than the local builds do, before and after.
  • On the post page and on /, the preview makes two requests fewer than main: one author avatar, as a redirect and its file. This matches a difference in the Link preload header of /blog. On main that header names seven images, the avatar among them. The optimizer URLs are longer, so on the preview it names six, and the avatar is a <link rel="preload"> tag in the page.
  • The optimizer answers image/webp: 156,394 bytes for the 1,401,775-byte cover of the post page. The first request for a cover took 0.41 to 0.85 s, and the next 0.06 to 0.12 s. The cover whose header was read answered x-vercel-cache: MISS, then HIT.
  • The page loads the GIF cover from /blog/the-astryx-cli/cover.gif: 151,605 bytes, image/gif, 11 frames.

Largest paint, median with the range of the loads, cold browser cache, 1440 px wide, scale 1:

Page Network Deployed main Preview
/blog Not throttled (9 loads) 416 ms (272 to 500) 432 ms (276 to 696)
/blog 10 Mbps, 40 ms (9 loads) 1,068 ms (964 to 1,268) 1,052 ms (960 to 1,176)
Post page Not throttled (9 loads) 504 ms (396 to 1,060) 372 ms (268 to 588)
Post page 10 Mbps, 40 ms (3 loads) 4,944 ms (4,924 to 5,144) 1,188 ms (1,164 to 1,324)

On /blog the two are equal within the range of the loads. On the post page the cover is the largest paint.

Largest paint on the local builds

Median of three loads, cold browser cache, optimizer cache filled, 1440 px wide, scale 1, local production builds.

Page Network Before After
/blog Not throttled (15 loads) 268 ms 264 ms
/blog 10 Mbps, 40 ms 448 ms 416 ms
/blog 1.6 Mbps, 150 ms 2,208 ms 2,188 ms
Post page Not throttled 248 ms 296 ms
Post page 10 Mbps, 40 ms 3,980 ms 660 ms
Post page 1.6 Mbps, 150 ms 24,316 ms 3,936 ms
  • On /blog the largest paint is the feature card's cover: a 9 KiB file before, 4 KiB after. The two columns are equal within the spread of the 15 loads: 244 to 2,392 ms before, 224 to 412 ms after.
  • On the post page the largest paint is the cover: 1,370 KiB before, 153 KiB after. With no throttle, its three loads were 240 to 412 ms before and 192 to 392 ms after, so that row shows no difference.
  • The first request for a cover after a deployment, or after the optimizer's copy expires, also pays for the resize: 0.07 to 0.80 s for each cover on the local build. With no copy yet and no throttle, one load of the post page painted its cover after 576 ms. The next load, with the copy made, took 396 ms.

No visible change

  • On all twelve rows, each cover has the same box, object-fit, and alt text before and after, every cover loads, and the layout shift score is the same.
  • At device scale 2, each measured cover has at least 2.4 image pixels per CSS pixel: the index grid card (366 CSS px), the article cover (752), the landing card on a tablet (786), and the one-column index card (652). Their source files are 1,920 pixels wide or more.
  • The GIF cover stays animated: the browser loads the same file.

Before and after, side by side:

Blog index grid, 1440 px Blog index grid before and after
Post page, 1440 px Post page before and after
Landing page blog section, 1440 px Landing page blog section before and after
Index grid cover at device scale 2 One index grid cover before and after at device scale 2

More pairs: the blog index first screen; at 390 px and scale 2, the blog index, a post page, and the landing section; crops at scale 2 of the article cover, a landing card on a tablet, and a one-column index card. Each image states the mean difference between its halves: 0.01 to 1.9 on a scale of 255.

Scope

Components: docsite blog covers (BlogCard, BlogFeatureCard, BlogArticle)

  • This PR has one primary intent.
  • Independently removable deltas were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm -F @astryxdesign/docsite test: 85 files pass and 1 is skipped (a skip that main has too); 988 tests pass. blog-cover-image.test.tsx is new (24 tests); blog-feature-cover.test.tsx expects the optimizer URL; template-image-loader.test.ts passes unchanged.
  • Mutation pass: 24 changes to the added and changed lines each fail a test. They change the width, the path rule, the format rule, the loader's use of that rule, and each render site. One more change, outside the added lines, sends the social card through the optimizer; the new metadata test fails.
  • pnpm -F @astryxdesign/docsite typecheck, ESLint in strict mode, Prettier, and the pre-commit checks pass.
  • pnpm -F @astryxdesign/docsite build passes on this head, and the docsite browser contracts (apps/docsite/e2e, 76 tests) pass on that build.
  • pnpm review:pre --head HEAD: 0 findings.
  • Browser measurements above: Playwright, Chromium 149. Firefox and Safari were not run; the change adds no markup that differs by browser.

The blog index, a post page, and the landing page's blog section load each
cover as the file a post names: PNG and JPEG files up to 3840 pixels wide
and 1.4 MB each. The blog index downloads 4,706 KiB of covers.

The three components that render a cover now ask the image optimizer for
it, through the existing optimizedImageUrl helper, 1920 pixels wide. Each
place has a layout where the cover is 650 to 975 CSS pixels wide, so a
smaller width is soft on a 2x screen there. One width also lets a card and
its article share one download.

The rule for which formats the optimizer converts moves from the template
image loader to that helper, so the loader and the covers share it. A
cover in another format, such as the animated GIF, keeps its own file, and
so does a URL on another host or a path with a query string. Page metadata
keeps the cover file's own URL for the social card.
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 18, 2026 1:21am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 18, 2026
@astracat-bot

astracat-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 18, 2026, 1:41 AM UTC

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · ed8e7ae

Storybook · Sandbox · built from this PR's head

Current run: The current CI run concluded cancelled. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: the three places that show a blog cover now load a PNG or JPEG cover through the image optimizer, and nothing else in the markup changes. Re-running the optimizer's own resize and encode over each committed cover reproduces the description's numbers — the index's ten covers come down from about 4,700 KiB to about 660 KiB, and the heaviest post cover from 1,369 KiB to 153 KiB. A production build of this revision confirms it end to end: every PNG and JPEG cover resolves through the optimizer at 1920 wide, the one GIF cover keeps its own URL, and the social card still names the cover file itself. CI has not run on this revision, because the pull request is a draft and every job skipped; the checks run once it is marked ready for review.

  • Worth knowing: a cover file replaced under its old name can serve the old picture for up to about eight hours, because the optimizer's answer for blog and image paths falls back to a four-hour lifetime, while the site's one-day photo rule covers only the landing and template-asset paths. The theme showcase photos already behave this way, so this is a follow-up to weigh, not something this change owes.
Claims and files checked

Review mode: full; reason: no-earlier-review

Claims

  • Index covers 4,706 KiB to 668 KiB: verified — measured 4,703 KiB to 664 KiB with the optimizer's own encode.
  • Post-page cover 1,370 KiB to 153 KiB: verified — 1,369 KiB to 153 KiB.
  • Landing section 623 KiB to 121 KiB: verified — 622 KiB to 120 KiB.
  • Only PNG and JPEG covers go through the optimizer, and the single GIF cover keeps its own URL: verified in the built page HTML.
  • A cover on another host, with a query string, or not root-relative keeps its own URL: verified against the optimizer's own validation rules and the new tests.
  • 1920 is a width the optimizer allows: verified in the framework's default device sizes and pinned by a new test.
  • Each place shows a cover at most 975 CSS pixels wide: verified from the components' own layout CSS (752, 659, 824, 975).
  • Page metadata keeps the cover file's own URL: verified in the built post page.
  • Docsite suite 85 files, 1 skipped, 988 tests, 24 new: verified, identical counts.
  • Typecheck passes: verified.
  • Docsite build passes: verified at this revision.
  • The optimizer's answer carries a four-hour lifetime: verified from the optimizer's code and the site's header rules.
  • Mutation pass of 24 edits each failing a test: partly verified — four representative edits (the width, one render site, the format rule, the path guard) each fail tests; the count itself was not reproduced.
  • Pre-review check with zero findings, the largest-paint table, and the deployed preview: not re-run here; they are the author's evidence and no part of this verdict rests on them.

Files

  • Template image loader: clear — the same format rule, now imported from the shared helper; its own tests pass unchanged.
  • Shared optimizer URL helper: clear — the format regex is unchanged, only exported, and the file header matches its new role.
  • New cover URL helper: clear — its two guards match exactly what the optimizer accepts.
  • BlogArticle, BlogCard, BlogFeatureCard: clear — only the image source expression changes in each.
  • New cover test file: clear — 24 tests covering each render site, the format rule and the rejected URL shapes.
  • Feature-card cover test: clear — the expectation is updated to the optimizer URL.
  • Post-author README: clear — the added guidance matches the behaviour.
  • Consistency: the five source files agree on one format rule and one width, and no other place in the site renders a post cover.

Automated review (maintainer link)

@nynexman4464
nynexman4464 marked this pull request as ready for review November 18, 2026 22:52
@nynexman4464
nynexman4464 merged commit 320ce44 into main Nov 19, 2026
280 of 298 checks passed
@github-actions
github-actions Bot deleted the nynexman4464/perf/docsite-blog-cover-images branch November 19, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — ed8e7ae5 Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant