TypeScript
perf(marketing): serve images at their display size (#9682)
Theo Browne8e3aa324b57d
diff --git a/apps/marketing/package.json b/apps/marketing/package.jsonindex 912faf88164..78c121d14fe 100644--- a/apps/marketing/package.json+++ b/apps/marketing/package.json@@ -11,7 +11,8 @@},"dependencies": {"@t3tools/shared": "workspace:*",- "astro": "^7.0.3"+ "astro": "^7.0.3",+ "sharp": "0.34.5"},"devDependencies": {"@astrojs/check": "^0.9.7",diff --git a/apps/marketing/public/app-desktop.webp b/apps/marketing/src/assets/app-desktop.webpsimilarity index 100%rename from apps/marketing/public/app-desktop.webprename to apps/marketing/src/assets/app-desktop.webpdiff --git a/apps/marketing/public/icon.webp b/apps/marketing/src/assets/icon.webpsimilarity index 100%rename from apps/marketing/public/icon.webprename to apps/marketing/src/assets/icon.webpdiff --git a/apps/marketing/src/layouts/Layout.astro b/apps/marketing/src/layouts/Layout.astroindex 686b555fd4c..0b022821a45 100644--- a/apps/marketing/src/layouts/Layout.astro+++ b/apps/marketing/src/layouts/Layout.astro@@ -1,4 +1,6 @@---+import { Image } from "astro:assets";+import appIcon from "../assets/icon.webp";import {ANDROID_PLAY_STORE_URL,GITHUB_REPOSITORY_URL,@@ -67,7 +69,17 @@ const {<footer class="footer"><div class="footer-inner"><div class="footer-brand">- <img src="/icon.webp" alt="" />+ <Image+ src={appIcon}+ alt=""+ width={20}+ height={20}+ densities={[1, 2, 3]}+ format="webp"+ quality={90}+ loading="lazy"+ decoding="async"+ /><span>© {new Date().getFullYear()} T3 Tools Inc · MIT licensed</span></div><div class="footer-links">diff --git a/apps/marketing/src/pages/index.astro b/apps/marketing/src/pages/index.astroindex 6b45f1a1bbc..1b47bf1512b 100644--- a/apps/marketing/src/pages/index.astro+++ b/apps/marketing/src/pages/index.astro@@ -1,4 +1,6 @@---+import { getImage } from "astro:assets";+import desktopScreenshot from "../assets/app-desktop.webp";import Layout from "../layouts/Layout.astro";import {ANDROID_PLAY_STORE_URL,@@ -8,6 +10,13 @@ import {} from "../lib/site";import { tweets } from "../lib/tweets";+const screenshot = await getImage({+ src: desktopScreenshot,+ widths: [864, 1180, 1728, 2360],+ format: "webp",+ quality: 90,+});+const desktopEndorsementRows = [tweets.filter((_, index) => index % 2 === 0),tweets.filter((_, index) => index % 2 === 1),@@ -80,14 +89,23 @@ const mobileEndorsementRows = [<div data-rise style="--d:520ms"><div class="hero-preview"><figure class="hero-screenshot-frame">- <img- src="/app-desktop.webp"- alt="T3 Code with a settled thread beside its pull request diff"- width="2880"- height="1800"- loading="eager"- decoding="async"- />+ <picture>+ <!-- Match the hidden mobile layout without requesting a screenshot. -->+ <source+ media="(max-width: 820px)"+ srcset="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"+ />+ <img+ src={desktopScreenshot.src}+ srcset={`${screenshot.srcSet.attribute}, ${desktopScreenshot.src} ${desktopScreenshot.width}w`}+ sizes="(max-width: 960px) min(864px, calc(100vw - 20px)), min(1180px, calc(100vw - 60px))"+ alt="T3 Code with a settled thread beside its pull request diff"+ width={desktopScreenshot.width}+ height={desktopScreenshot.height}+ loading="eager"+ decoding="async"+ />+ </picture></figure></div></div>diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 8d5ee2875cc..d740a25572a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -206,6 +206,9 @@ importers:astro:specifier: ^7.0.3version: 7.0.3(@astrojs/[email protected])(@emnapi/[email protected])(@emnapi/[email protected])(@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])+ sharp:+ specifier: 0.34.5+ version: 0.34.5devDependencies:'@astrojs/check':specifier: ^0.9.7@@ -12787,8 +12790,7 @@ snapshots:'@iarna/[email protected]': {}- '@img/[email protected]':- optional: true+ '@img/[email protected]': {}'@img/[email protected]':optionalDependencies:@@ -20293,7 +20295,6 @@ snapshots:'@img/sharp-win32-arm64': 0.34.5'@img/sharp-win32-ia32': 0.34.5'@img/sharp-win32-x64': 0.34.5- optional: truedependencies: