Skip to content

Commit 97ee33d

Browse files
rsbhclaude
andcommitted
docs: add image optimization documentation
Covers format negotiation, query params (w/q), allowed values, API endpoint, caching, and warmup behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 518d5dc commit 97ee33d

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
title: Image Optimization
3+
description: Automatic image optimization with on-demand resizing and format conversion.
4+
order: 5
5+
---
6+
7+
# Image Optimization
8+
9+
Chronicle automatically optimizes content images via an on-demand `/api/image` endpoint. Images are resized, converted to modern formats (WebP/AVIF), and cached on disk.
10+
11+
## How It Works
12+
13+
1. The remark plugin rewrites all image URLs to route through `/api/image`
14+
2. On first request, the image is resized and converted based on browser support
15+
3. The result is cached — subsequent requests are served instantly
16+
4. On server start, all content images are pre-cached (warmup)
17+
18+
## Format Negotiation
19+
20+
The endpoint reads the browser's `Accept` header and serves the best format:
21+
22+
| Browser sends | Format served |
23+
|---|---|
24+
| `Accept: image/avif` | AVIF |
25+
| `Accept: image/webp` | WebP |
26+
| Neither | Original (resized only) |
27+
28+
SVG images are passed through unchanged.
29+
30+
## Query Parameters
31+
32+
Control image output directly in markdown using query parameters:
33+
34+
```md
35+
![Screenshot](screenshot.png?w=640&q=90)
36+
```
37+
38+
### Width (`w`)
39+
40+
Sets the output width in pixels. The image is resized proportionally (height auto-calculated). Images are never enlarged beyond their original size.
41+
42+
**Allowed values:**
43+
44+
| Width | Use case |
45+
|---|---|
46+
| `320` | Small thumbnails, mobile icons |
47+
| `640` | Mobile content images |
48+
| `768` | Tablet content images |
49+
| `1024` | Default — desktop content |
50+
| `1280` | Wide content areas |
51+
| `1536` | Large displays |
52+
| `1920` | Full-width hero images |
53+
54+
Default: `1024`
55+
56+
### Quality (`q`)
57+
58+
Sets the compression quality. Lower values produce smaller files with more compression artifacts.
59+
60+
**Allowed values:**
61+
62+
| Quality | File size | Use case |
63+
|---|---|---|
64+
| `60` | Smallest | Thumbnails, previews |
65+
| `75` | Balanced | Default — content images |
66+
| `90` | High quality | Screenshots with text |
67+
| `100` | Maximum | Lossless-like output |
68+
69+
Default: `75`
70+
71+
## Examples
72+
73+
```md
74+
<!-- Default: 1024w, quality 75 -->
75+
![Overview](overview.png)
76+
77+
<!-- Small thumbnail -->
78+
![Thumb](thumb.png?w=320&q=60)
79+
80+
<!-- High quality screenshot -->
81+
![UI](dashboard.png?w=1280&q=90)
82+
83+
<!-- Width only, default quality -->
84+
![Photo](photo.png?w=640)
85+
86+
<!-- Quality only, default width -->
87+
![Chart](chart.png?q=90)
88+
```
89+
90+
## API Endpoint
91+
92+
```
93+
GET /api/image?url=/_content/docs/photo.png&w=640&q=75
94+
```
95+
96+
| Parameter | Required | Description |
97+
|---|---|---|
98+
| `url` | Yes | Content image path (must start with `/_content/`) |
99+
| `w` | Yes | Output width (must be an allowed value) |
100+
| `q` | No | Quality 1-100 (snapped to nearest allowed value) |
101+
102+
### Response Headers
103+
104+
```
105+
Content-Type: image/webp (or image/avif, or original mime)
106+
Cache-Control: public, max-age=31536000, immutable
107+
Vary: Accept
108+
```
109+
110+
## Cache
111+
112+
Optimized images are cached using Nitro storage with the `fs` driver at `.cache/images/`. Cache persists across server restarts.
113+
114+
The warmup process pre-caches all content images as WebP at default width (1024) and quality (75) when the server starts.

0 commit comments

Comments
 (0)