Skip to main content
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 rewrites data-src to optimized Tenbyte URLs at runtime.

Prerequisites

1. Create the wrapper component

src/components/TenbyteImage.astro
The SDK looks for data-src and rewrites it on load.

2. Load the Tenbyte SDK in your layout

src/layouts/BaseLayout.astro
Replace images.yoursite.com with the domain where your master images live, and your-distribution.tenbytecdn.com with your Tenbyte hostname.

3. Use it in pages

src/pages/index.astro

Pre-applied transforms

You can put query params directly in src — they’re preserved through the rewrite:
Or compose params per breakpoint with a small helper:
src/lib/img.ts

Verify

After the SDK loads in the browser, 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