Skip to content

Commit 3e75f3b

Browse files
committed
perf(marketing): serve images at their display size
1 parent 887ece3 commit 3e75f3b

6 files changed

Lines changed: 45 additions & 13 deletions

File tree

‎apps/marketing/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"dependencies": {
1313
"@t3tools/shared": "workspace:*",
14-
"astro": "^7.0.3"
14+
"astro": "^7.0.3",
15+
"sharp": "0.34.5"
1516
},
1617
"devDependencies": {
1718
"@astrojs/check": "^0.9.7",
File renamed without changes.

‎apps/marketing/src/layouts/Layout.astro‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
import { Image } from "astro:assets";
3+
import appIcon from "../assets/icon.webp";
24
import {
35
ANDROID_PLAY_STORE_URL,
46
GITHUB_REPOSITORY_URL,
@@ -67,7 +69,17 @@ const {
6769
<footer class="footer">
6870
<div class="footer-inner">
6971
<div class="footer-brand">
70-
<img src="/icon.webp" alt="" />
72+
<Image
73+
src={appIcon}
74+
alt=""
75+
width={20}
76+
height={20}
77+
densities={[1, 2, 3]}
78+
format="webp"
79+
quality={90}
80+
loading="lazy"
81+
decoding="async"
82+
/>
7183
<span>&copy; {new Date().getFullYear()} T3 Tools Inc · MIT licensed</span>
7284
</div>
7385
<div class="footer-links">

‎apps/marketing/src/pages/index.astro‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
import { getImage } from "astro:assets";
3+
import desktopScreenshot from "../assets/app-desktop.webp";
24
import Layout from "../layouts/Layout.astro";
35
import {
46
ANDROID_PLAY_STORE_URL,
@@ -8,6 +10,13 @@ import {
810
} from "../lib/site";
911
import { tweets } from "../lib/tweets";
1012
13+
const screenshot = await getImage({
14+
src: desktopScreenshot,
15+
widths: [864, 1180, 1728, 2360],
16+
format: "webp",
17+
quality: 90,
18+
});
19+
1120
const desktopEndorsementRows = [
1221
tweets.filter((_, index) => index % 2 === 0),
1322
tweets.filter((_, index) => index % 2 === 1),
@@ -80,14 +89,23 @@ const mobileEndorsementRows = [
8089
<div data-rise style="--d:520ms">
8190
<div class="hero-preview">
8291
<figure class="hero-screenshot-frame">
83-
<img
84-
src="/app-desktop.webp"
85-
alt="T3 Code with a settled thread beside its pull request diff"
86-
width="2880"
87-
height="1800"
88-
loading="eager"
89-
decoding="async"
90-
/>
92+
<picture>
93+
<!-- Match the hidden mobile layout without requesting a screenshot. -->
94+
<source
95+
media="(max-width: 820px)"
96+
srcset="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
97+
/>
98+
<img
99+
src={desktopScreenshot.src}
100+
srcset={`${screenshot.srcSet.attribute}, ${desktopScreenshot.src} ${desktopScreenshot.width}w`}
101+
sizes="(max-width: 960px) min(864px, calc(100vw - 20px)), min(1180px, calc(100vw - 60px))"
102+
alt="T3 Code with a settled thread beside its pull request diff"
103+
width={desktopScreenshot.width}
104+
height={desktopScreenshot.height}
105+
loading="eager"
106+
decoding="async"
107+
/>
108+
</picture>
91109
</figure>
92110
</div>
93111
</div>

‎pnpm-lock.yaml‎

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)