WebP Image Support
WebP Image Support
This blog supports WebP images with automatic fallbacks to JPEG/PNG for better performance and compatibility.
What is WebP?
WebP is a modern image format that provides superior compression compared to JPEG and PNG:
- 25-35% smaller file sizes with same visual quality
- Supports both lossy and lossless compression
- 95%+ browser support (Chrome, Firefox, Edge, Safari 14+)
How It Works
Automatic Generation (New Posts)
When you create a blog post via GitHub issues, the workflow automatically:
- Downloads images from the issue
- Optimizes JPEG/PNG images
- Generates WebP versions of all images
- Commits both versions to the repository
No manual intervention needed!
For Existing Images
Run the batch conversion script:
1
./scripts/generate-webp.sh
This will:
- Scan
for JPEG and PNG files1
assets/img/
- Generate WebP versions (filename.webp)
- Keep original files as fallbacks
- Show savings report
Using WebP Images in Posts
Option 1: WebP Include (Recommended)
Use the include for automatic WebP with fallback:1
webp-image.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<figure class="aligncenter">
<picture>
<source srcset="/assets/img/photo.webp" type="image/webp">
<img src="/assets/img/photo.jpg"
alt="Description of image"
loading="lazy"
decoding="async">
</picture>
<figcaption>Optional caption text</figcaption>
</figure>
What it generates:
1
2
3
4
<picture>
<source srcset="/assets/img/photo.webp" type="image/webp">
<img src="/assets/img/photo.jpg" alt="Description" loading="lazy" decoding="async">
</picture>
Option 2: Manual Picture Element
For full control, use HTML picture element:
1
2
3
4
5
6
7
<picture>
<source srcset="/assets/img/photo.webp" type="image/webp">
<img src="/assets/img/photo.jpg"
alt="Description"
loading="lazy"
decoding="async">
</picture>
With Captions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<figure class="aligncenter">
<picture>
<source srcset="/assets/img/photo.webp" type="image/webp">
<img src="/assets/img/photo.jpg"
alt="Mountain landscape"
loading="lazy"
decoding="async">
</picture>
<figcaption>Beautiful mountain view at sunset</figcaption>
</figure>
Generates:
1
2
3
4
5
6
7
<figure class="aligncenter">
<picture>
<source srcset="/assets/img/photo.webp" type="image/webp">
<img src="/assets/img/photo.jpg" alt="Mountain landscape" loading="lazy">
</picture>
<figcaption>Beautiful mountain view at sunset</figcaption>
</figure>
Include Parameters
| Parameter | Required | Description | ||||||
|---|---|---|---|---|---|---|---|---|
|
Yes | Path to original image (JPEG/PNG) | ||||||
|
No | Alt text for accessibility | ||||||
|
No | CSS class (e.g., , ) |
||||||
|
No | Caption text (wraps in ) |
Browser Support
| Browser | WebP Support |
|---|---|
| Chrome | ✅ All versions |
| Firefox | ✅ 65+ |
| Edge | ✅ All versions |
| Safari | ✅ 14+ (iOS 14+) |
| Opera | ✅ 32+ |
Fallback: Older browsers automatically use JPEG/PNG from the tag.1
<img>
Performance Impact
Before WebP
- JPEG: 500KB
- PNG: 800KB
After WebP
- WebP: 350KB (30% smaller than JPEG)
- WebP: 550KB (31% smaller than PNG)
Page load improvements:
- 20-40% faster LCP (Largest Contentful Paint)
- Reduced bandwidth usage
- Better Core Web Vitals scores
File Organization
1
2
3
4
5
assets/img/
├── photo.jpg # Original (fallback)
├── photo.webp # WebP version (served first)
├── banner.png # Original (fallback)
└── banner.webp # WebP version (served first)
Workflow Integration
The issue-to-post workflow () automatically:1
.github/workflows/issue-to-post.yml
- Downloads images from GitHub issues
- Optimizes JPEG/PNG (resize, compress, strip metadata)
- Generates WebP versions with
1
cwebp -q 85
- Commits both original and WebP versions
Quality Settings
- WebP Quality: 85 (balances size and quality)
- JPEG Quality: 85 (for fallback)
- Max Dimensions: 1920x1920px
Testing
Verify WebP Support
- Open blog post in Chrome DevTools
- Network tab → Filter by “Img”
- Look for
files being loaded1
.webp
- Check fallback in Safari 13 or older browsers
Performance Testing
1
2
3
4
5
6
# Compare file sizes
ls -lh assets/img/photo.jpg
ls -lh assets/img/photo.webp
# Test with PageSpeed Insights
https://pagespeed.web.dev/
Migration Guide
For Existing Posts
- Generate WebP versions:
1
./scripts/generate-webp.sh
- Update post images (optional - for best results):
- Replace
tags with `1
<img>
- Replace
`
- Or use
elements manually1
<picture>
- Verify:
- Check both .jpg and .webp files exist
- Test in browser with DevTools
For New Posts
✅ No action needed! The workflow handles everything automatically.
Troubleshooting
WebP Not Loading
- Check both .jpg and .webp files exist in
1
assets/img/
- Verify
comes before1
<source>
in picture element1
<img>
- Check browser supports WebP (95%+ do)
File Size Too Large
- Adjust quality in workflow (currently 85)
- Resize images to max 1920px
- Consider converting PNG to JPEG first
Generation Script Fails
1
2
3
# Install WebP tools
brew install webp # macOS
sudo apt-get install webp # Linux
Best Practices
- ✅ Always include original JPEG/PNG as fallback
- ✅ Use
include for consistency1
webp-image.html
- ✅ Add descriptive alt text for accessibility
- ✅ Test in multiple browsers
- ✅ Run
after bulk image adds1
generate-webp.sh