Repository navigation
perf(docsite): load blog cover images through the image optimizer - #12536
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
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.
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.
/blog(10 covers)astryx-cli-build-command)/(3 covers in "Stay in the know")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 carriesmax-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
BlogCard,BlogFeatureCard, andBlogArticlerender<img src={post.coverImage}>, the full-size file.Each delta maps to that problem:
src/lib/blog/coverImage.tsblogCoverUrl(coverImage)returns the optimizer URL from the existingoptimizedImageUrlhelper for a root-relative PNG or JPEG path. Any other cover keeps its own URL.BlogCard,BlogFeatureCard,BlogArticle<img>loadsblogCoverUrl(post.coverImage). Nothing else in the markup changes.src/lib/optimizedImageUrl.mjs,scripts/template-image-loader.mjsisOptimizedFormat. The loader and the covers then use one rule. The loader's output does not change.src/content/blog/README.mdNo 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.
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:
/blogcover bytesBlogCard. 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.srcsetandsizessizesvalue 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
/blog/the-astryx-cli/cover.gifis 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.Left as it is
og:imageandtwitter:imagekeep the cover file's own URL, because a crawler needs the file itself. A test pins this for a post with a cover.one-month-of-astryx/community-showcase.png(2,623 KiB) andastryx-meetup-are-design-systems-still-valuable/photo-07.jpg(814 KiB).loading="lazy". The article cover and the index feature card are the largest paint on their pages.Authority
spec:AST-033andarchitecture:knowledge-contractsare linked toapps/docsite/**. None of their claims covers the URL an image loads from, andpnpm specs:for --diff origin/mainroutes 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 sameoptimizedImageUrlhelper.Change and evidence
Status of the evidence:
next build, thennext start) ofmainand 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.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.
/blog/blog/blog/blog////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 deployedmain(astryx-git-main-fbopensource.vercel.app), with the same browser and method./blog/blog/blog/blog/////, the preview makes two requests fewer thanmain: one author avatar, as a redirect and its file. This matches a difference in theLinkpreload header of/blog. Onmainthat 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.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 answeredx-vercel-cache: MISS, thenHIT./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:
main/blog/blogOn
/blogthe 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.
/blog/blog/blog/blogthe 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.No visible change
object-fit, and alt text before and after, every cover loads, and the layout shift score is the same.Before and after, side by side:
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)Testing
pnpm -F @astryxdesign/docsite test: 85 files pass and 1 is skipped (a skip thatmainhas too); 988 tests pass.blog-cover-image.test.tsxis new (24 tests);blog-feature-cover.test.tsxexpects the optimizer URL;template-image-loader.test.tspasses unchanged.pnpm -F @astryxdesign/docsite typecheck, ESLint in strict mode, Prettier, and the pre-commit checks pass.pnpm -F @astryxdesign/docsite buildpasses on this head, and the docsite browser contracts (apps/docsite/e2e, 76 tests) pass on that build.pnpm review:pre --head HEAD: 0 findings.