data-src to optimized Tenbyte URLs at runtime.
Prerequisites
- Astro 3+.
- A Tenbyte distribution with Image Optimizer enabled.
- The Tenbyte CDN hostname for your account.
1. Create the wrapper component
src/components/TenbyteImage.astro
data-src and rewrites it on load.
2. Load the Tenbyte SDK in your layout
src/layouts/BaseLayout.astro
3. Use it in pages
src/pages/index.astro
Pre-applied transforms
You can put query params directly insrc — they’re preserved through the rewrite:
src/lib/img.ts
Verify
data-src becomes src. Inspect with DevTools → Network to see the actual request URL.
Tips
- Always
loading="lazy"below the fold. - Cap widths — only request widths your design uses.
format=auto— let the edge pick WebP / AVIF.- SSR works — output is plain
<img>. The SDK runs only on the client. - Static builds work — Tenbyte still handles transforms at request time.