Skip to content

perf(ui-samples): serve mobile sample cards through next/image - #758

Open
dgaponov wants to merge 1 commit into
mainfrom
seo/optimize-card-images
Open

perf(ui-samples): serve mobile sample cards through next/image#758
dgaponov wants to merge 1 commit into
mainfrom
seo/optimize-card-images

Conversation

@dgaponov

@dgaponov dgaponov commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Карточки UI-семплов рендерились обычным <img> напрямую из ассета, минуя оптимизатор, который остальная страница уже использует. Исходники до 2212px шириной, отображаются примерно во всю ширину вьюпорта. Блок скрыт выше брейкпоинта sm, поэтому лишний мегабайт платили только мобильные пользователи.

Главная на 390px, прод-сборка, все семь карточек: 1234 → 305 КБ (−75%). Худшая, hotel-booking, 329 → 72 КБ.

Заодно у карточек не было alt — теперь используется локализованный заголовок семпла.

width: 100%; height: auto в SCSS обязателен: next/image проставляет атрибуты размеров, без этого карточка раскладывалась в натуральные 2216px вместо 508px.

Десктоп не затронут — запросов карточек ноль до и после. E2E эту правку не покрывает: снапшот снимается на десктопе, где блок скрыт. Проверял вручную на 390px.

🤖 Generated with Claude Code

The mobile UI-samples cards rendered a plain <img> pointing straight at the
imported asset, bypassing the image optimizer that the rest of the page
already uses. The sources are up to 2212px wide while the cards display at
roughly viewport width, so the originals were served in full.

Pass the imported StaticImageData to next/image instead of just its `.src`,
so the images are resized per device and converted to WebP/AVIF.

Measured on the homepage at a 390px viewport, production build, fresh
profile, all seven cards scrolled into view:

    card images   1234 kB -> 305 kB   (-929 kB, -75%)

    hotel-booking  329 -> 72     listing       126 -> 28
    dashboard      189 -> 32     osn           126 -> 40
    mail           183 -> 52     kubernetes    120 -> 34
    task-tracker   163 -> 46

The cards also had no alt attribute at all. They now use the sample's
localised title ("Dashboard", "Booking page", ...), which the block already
had available.

The SCSS needs `width: 100%; height: auto` because next/image emits
intrinsic width/height attributes; without it the card laid out at the
source image's natural width of 2216px instead of the container's 508px.
That was caught in a browser and fixed, not shipped.

Desktop is unaffected: the block is display:none above the sm breakpoint and
issues zero card requests there, before and after.

Build, lint and typecheck pass. E2E not run - Playwright browsers are not
installed locally; these are visual changes, so the snapshot suite is worth
running before merge.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@dgaponov
dgaponov marked this pull request as ready for review September 11, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant