🌐 External Image Optimization

This page demonstrates how to optimize external images in Astro using various techniques.

📸 External Image Examples

Method 1: Regular img tag with optimization attributes

External image example 1

Uses loading="lazy" and decoding="async" for performance

Method 2: Responsive image with srcset

Responsive external image

Uses srcset for responsive images

Method 3: Picture element with multiple formats

Picture element example

Uses picture element for format fallbacks

đŸ› ī¸ External Image Optimization Techniques

🚀 Lazy Loading

Use loading="lazy" to defer loading images until they're needed

<img loading="lazy" ... />

⚡ Async Decoding

Use decoding="async" to prevent blocking the main thread

<img decoding="async" ... />

📱 Responsive Images

Use srcset and sizes for different screen sizes

<img srcset="small.jpg 300w, large.jpg 800w" />

đŸ–ŧī¸ Modern Formats

Use <picture> element for WebP/AVIF with fallbacks

<picture>
  <source srcset="image.webp" type="image/webp">
  <img src="image.jpg" alt="...">
</picture>

â˜ī¸ Image CDN Services

For better external image optimization, consider using image CDN services:

Cloudinary

Automatic optimization, format conversion, and resizing

https://res.cloudinary.com/demo/image/fetch/w_400,f_auto,q_auto/https://example.com/image.jpg

ImageKit

Real-time image optimization and transformation

https://ik.imagekit.io/demo/tr:w-400,f-auto,q-auto/https://example.com/image.jpg

Cloudflare Images

Global CDN with automatic optimization

https://imagedelivery.net/account/image-id/w=400,f=auto,q=auto

⚡ Performance Tips

â„šī¸ External vs Internal Images

Aspect Internal Images External Images
Optimization Automatic by Astro Manual or CDN-based
Build Time Processed during build No build processing
Caching Cached with site Depends on external server
Control Full control Limited control
← Back to Home