Use Tenbyte Image Optimization in Astro to deliver lighter images with zero build-time work. Drop in a small component and the Tenbyte JS SDK; the SDK rewritesDocumentation Index
Fetch the complete documentation index at: https://docs.tenbyte.io/llms.txt
Use this file to discover all available pages before exploring further.
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.
Troubleshooting
| Symptom | Fix |
|---|---|
| Images don’t load | SDK script blocked / not loaded. Check Network tab; confirm tenbyte.min.js is fetched. |
| Original src is requested | The host in src doesn’t match TENBYTE_CONFIG.hosts[0].current. |
| Wrong dimensions on Retina | Pass dpr=2 or rely on srcset widths. |