Variants and CDN
For every image you upload, Nooknear generates WebP variants in a few preset sizes and serves them through the Cloudflare CDN. This page covers the default variants, how CDN URLs are structured, the token parameter in those URLs, and how to use the variants with srcset.
Default variants
| Variant | Size | Notes |
|---|---|---|
thumb |
150 × 150 | Square, center-cropped (cover). For lists and avatars. |
small |
400 px wide | Height follows the aspect ratio. |
medium |
800 px wide | Height follows the aspect ratio. |
large |
1200 px wide | Height follows the aspect ratio. |
jpeg |
Longest side up to 2048 px | Only if "jpeg" was requested in outputFormats. See Uploads. |
All WebP variants are encoded with the same settings (quality 85). The response includes the actual width, height, sizeBytes and mimeType for each variant; use those fields rather than hard-coded numbers when you build a srcset.
"variants": {
"thumb": { "url": "https://cdn.nooknear.com/.../thumb.webp?token=...", "width": 150, "height": 150, "sizeBytes": 6012, "mimeType": "image/webp" },
"small": { "url": "https://cdn.nooknear.com/.../small.webp?token=...", "width": 400, "height": 267, "sizeBytes": 17020, "mimeType": "image/webp" },
"medium": { "url": "https://cdn.nooknear.com/.../medium.webp?token=...", "width": 800, "height": 533, "sizeBytes": 45110, "mimeType": "image/webp" },
"large": { "url": "https://cdn.nooknear.com/.../large.webp?token=...", "width": 1200, "height": 800, "sizeBytes": 48210, "mimeType": "image/webp" }
}
CDN URL format
https://cdn.nooknear.com/{tenantId}/{resourceType}/{resourceId}/{assetId}/{variant}.webp?token={token}
For the JPEG variant the file name is jpeg.jpg. The CDN responds with a Content-Type that matches the extension (image/webp or image/jpeg).
Rather than building URLs yourself, store and use the url field from the API response as-is. URLs are stable: the same asset always gets the same URL, so it’s safe to keep them in your database.
CDN responses carry a long-lived cache header (Cache-Control: public, max-age=31536000, immutable). To change an image, upload a new one instead of trying to overwrite the old file; a new assetId means a new URL, so you never fight stale caches.
The token parameter
The token in each URL is a per-asset HMAC signature:
- It doesn’t expire. It stays valid until the asset is deleted.
- It doesn’t need an API key. Browsers, email clients and third parties such as Instagram can fetch the URL directly.
- It can’t be guessed. Without the right
tokenthe URL returns401, so knowing anassetIdisn’t enough to fetch the image. - It’s independent of your API key. Rotating the key doesn’t break existing URLs.
In other words, these are “unlisted but shareable” links: anyone with the URL can see the image. If you need per-user authorization, only show the URLs to authorized users.
The download-token endpoint
POST /v1/media/download-token returns the same signature used in CDN URLs. It’s useful if you want to build URLs on your side:
curl -X POST https://api.nooknear.com/v1/media/download-token \
-H "X-API-Key: $NOOKNEAR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"resourceType": "product",
"resourceId": "42",
"assetId": "3f6c2a8e-1b4d-4c1e-9a77-5e2f0d8b9c10"
}'
{ "token": "9b1e...c04a", "expiresAt": null }
Current behavior: expiresInSeconds is accepted (max 86400, default 3600), but tokens are not time-limited yet; expiresAt is always null and the token stays valid until the asset is deleted. To get a token that matches a CDN URL, send all three of resourceType, resourceId and assetId.
Using srcset and sizes
Variants are meant to let the browser pick the right file for the viewport width and pixel density. thumb is a cropped square, so leave it out of srcset.
<img
src="https://cdn.nooknear.com/.../medium.webp?token=..."
srcset="
https://cdn.nooknear.com/.../small.webp?token=... 400w,
https://cdn.nooknear.com/.../medium.webp?token=... 800w,
https://cdn.nooknear.com/.../large.webp?token=... 1200w"
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 600px"
width="1200" height="800"
alt="Grilled adana kebab with charred pepper and tomato"
loading="lazy"
decoding="async">
sizesdescribes the image’s display width on the page. In this example it’s full width on phones, half width on tablets and 600 px on desktop.widthandheightreserve space while the page loads and prevent layout shift (CLS). Thelargevariant’s values are enough; the browser derives the aspect ratio from them.- If this is the largest image on the page (the LCP element), use
fetchpriority="high"instead ofloading="lazy".
To build a srcset from the API response in a JavaScript component:
function toSrcset(variants) {
return ['small', 'medium', 'large']
.filter((name) => variants[name])
.map((name) => `${variants[name].url} ${variants[name].width}w`)
.join(', ');
}
No egress fees
Images are stored in Cloudflare R2 and served through Cloudflare’s CDN by a Worker. R2 doesn’t charge for egress bandwidth, so Nooknear doesn’t pass on per-GB traffic fees either; plans include delivery with no bandwidth fees under a fair-use policy. See the pricing page.
Coming soon: on-the-fly URL transforms
Today you get the preset WebP variants above plus the optional JPEG variant. Planned behavior:
- Parameters such as
?w=600&h=400&fit=cover&format=avif&q=75will return any size, crop, format and quality on demand. - AVIF output will be added.
- The best format will be picked automatically from the browser’s
Acceptheader.
This page will be updated when these ship.