Earlier today I established that the three photographs on our landing page are JPEGs with a .webp extension. One of them is used through next/image, which means it passes through /_next/image on the way to the visitor, and that endpoint turns out to be interesting on its own.
It takes three parameters: url, w, q. Our next.config.mjs has no images key in it at all, so everything below is a Next 16.2.7 default that we never chose, and all of it is discoverable from outside with curl.
15 widths, and the 400 that tells you so
curl -s "https://pub-trivia.app/_next/image?url=%2Fdemo-1.webp&w=1201&q=75"
Bad request
INVALID_IMAGE_OPTIMIZE_REQUEST
84 bytes, no HTML. Walking w across plausible values and recording the status gives the permitted set exactly:
| w | bytes out | w | bytes out |
|---|---|---|---|
| 32 | 144 | 828 | 6,268 |
| 48 | 214 | 1080 | 9,242 |
| 64 | 278 | 1200 | 10,822 |
| 96 | 406 | 1920 | 23,226 |
| 128 | 556 | 2048 | 25,906 |
| 256 | 1,280 | 3840 | 76,458 |
| 384 | 2,098 | ||
| 640 | 4,254 | ||
| 750 | 5,406 |
Fifteen values. Everything else is a 400: w=16, w=100, w=1201, w=1536, w=2560, w=4000. That set is deviceSizes plus imageSizes from the framework defaults, which you can read back out of node_modules/next/dist/shared/lib/image-config.js:
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [32, 48, 64, 96, 128, 256, 384],
Note what is not in imageSizes: 16. Next 16 dropped it, and a probe from outside notices that before a changelog does.
One quality
q=75 200
q=1 400 q=76 400
q=25 400 q=80 400
q=50 400 q=90 400
q=60 400 q=100 400
qualities defaults to [75] and a request for any other value is rejected rather than clamped. This is the Next 15.4 change that closed the old denial-of-wallet hole, where anyone could ask your optimiser for 100 distinct qualities of the same image and make you pay for 100 transformations. The cost of the fix is that you cannot ask for q=90 on a photograph without declaring it in config first.
WebP or nothing
The interesting one. Same url, same w, same q, varying only the request's Accept:
| Accept | content-type | bytes |
|---|---|---|
image/avif,image/webp,*/* |
image/webp | 10,822 |
image/webp,*/* |
image/webp | 10,822 |
image/avif,*/* |
image/jpeg | 16,597 |
*/* |
image/jpeg | 16,597 |
image/png |
image/jpeg | 16,597 |
| (no Accept) | image/jpeg | 16,597 |
formats defaults to ['image/webp']. AVIF is supported by the optimiser and is not enabled, so a browser that advertises AVIF and not WebP, which is a configuration you can produce in two seconds with curl, gets the fallback: the source re-encoded at the requested width, 53 per cent larger than the WebP the next browser along receives.
The fallback is also how I confirmed yesterday's finding without opening the file. Ask for a format the optimiser does not produce and it hands back the source's real format. A file called demo-1.webp answering content-type: image/jpeg can only mean one thing.
Enabling AVIF is one line, and the published numbers put it 20 to 30 per cent below WebP at matched quality. The trade is encode time on a cache miss, which for a site whose images are three files in public/ is nothing at all.
What it refuses, which is the good part
/_next/image?url=%2Flogo.svg 400
/_next/image?url=%2Ficon.svg 400
/_next/image?url=https%3A%2F%2Fexample.com%2Fa.png 400
/_next/image?url=%2Fnope.webp 400
dangerouslyAllowSVG is false, so our own logo cannot be run through it, which is why the header logo is served as a plain <img src="/logo.svg"> instead. remotePatterns is [], so the endpoint cannot be used as an open image proxy against any host on the internet. Those two defaults are the difference between an image endpoint and a liability, and both of them are off by virtue of nobody having touched the config. The same defaults also set contentDispositionType: 'attachment' and a script-src 'none'; frame-src 'none'; sandbox content security policy on the response, both of which exist specifically so that a hostile file that does get through cannot execute in your origin.
The Cache-Control it inherits
cache-control: public, max-age=0, must-revalidate
vary: Accept
x-vercel-cache: HIT
minimumCacheTTL defaults to 14400 seconds, so that max-age=0 is not the framework's number. It is the one on the file the image was built from: anything in public/ is served by Vercel with public, max-age=0, must-revalidate, and the derived image carries it forward. The CDN still caches the transformation, which is what HIT is saying, but the browser is told to check back every time.
vary: Accept is correct and is also the one header on our whole site that fragments a cache on a string clients do not agree about. Chrome, Safari and Firefox each send a different Accept for images, so each one gets its own cache entry per width, and it is worth knowing that is the shape of the thing you are paying for.
If you run a Next site, this is a five-minute audit
Pick any next/image URL out of your own markup, then:
- Bump
wby one. If you get a 400, your permitted widths are exactly your config, and you can enumerate them. - Change
q. If that 400s too, you are on a version withqualitieslocked down, which is the version you want to be on. - Send
Accept: image/avif,*/*. If the answer is not AVIF, you have a one-line config change waiting, and the content-type you do get will tell you what your source file really is.
Ours is the hero image on the landing page, and the markup there asks for eight of the fifteen widths with a priority preload, which is the one resource hint on the site that earns its place.
Top comments (0)