Skip to content

docs: lazy-load light/dark images so the hidden one isn't fetched - #275

Merged
domoritz merged 1 commit into
apple:mainfrom
Yigtwxx:docs/lazy-theme-images
Oct 5, 2026
Merged

domoritz merged 1 commit into
apple:mainfrom
Yigtwxx:docs/lazy-theme-images

Conversation

@Yigtwxx

@Yigtwxx Yigtwxx commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #222 (comment)

The docs show a light and a dark version of the same image and hide one of them with .light-only / .dark-only (display: none). The browser still downloads the hidden one. On the overview, tool, embedding-view and embedding-view-mosaic pages that's an extra ~2 MB png per page, and the examples page fetches 9 extra thumbnails.

This adds loading="lazy" to those images. A lazy image with display: none isn't loaded, so only the visible version is fetched, and the other one loads when you switch the theme. I checked it in Chrome with the same markup and css: in light mode the dark images are no longer requested, and switching to dark loads them.

On overview and tool the visible image is near the top of the page, so lazy can start it a little later, but that seemed better than downloading 2 MB that isn't shown.

@domoritz
domoritz merged commit b5f65a2 into apple:main Oct 5, 2026
8 checks passed
@Yigtwxx
Yigtwxx deleted the docs/lazy-theme-images branch October 6, 2026 15:36
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.

2 participants