Discussion about adding brotli compression to Sanity's CDN

24 replies
Last updated: Mar 4, 2021
Any thoughts about supporting brotli as well as gzip?
AI Update

Great question! Based on the conversation history from the Sanity community, Brotli compression is already supported on Sanity's infrastructure, though the rollout happened in different phases.

Here's what's currently supported:

API CDN / Live CDN: Brotli compression was added in March 2021 for content API responses (your GROQ query results). You can verify this by looking for content-encoding: br in the response headers when your client sends Accept-Encoding: br.

Asset CDN: Brotli compression is also supported for media assets served through cdn.sanity.io, including images, videos, and SVGs. The Asset CDN documentation mentions that both Brotli and Gzip compression are supported, with the CDN automatically choosing the best compression based on what your client's browser supports via the Accept-Encoding header.

The implementation is pretty seamless - assets are compressed with Brotli when cached in Varnish, and automatically transcoded to Gzip if the client doesn't support Brotli. According to the team's testing, performance impact is negligible (around 1ms during the initial cache fetch), and compression improvements can range from 6% to 25% depending on the content type, with SVGs seeing particularly good results.

So you should already be getting Brotli compression automatically if your HTTP client is sending the appropriate Accept-Encoding headers! No configuration needed on your end.

I’ll have a look at how we can support it, thanks for the tip!
Sweet, could be as easy as your CDN settings :)
You would think that 😄 Of course Google CDN leaves compression to the servers behind it, and my particular server version is still waiting for brotli support. I'll keep an eye on it though!
Cheers Nicolas :)
Especially funny since Brotli is from google 😂
Hm our apicdn might be able to support brotli, would that be interesting? Or are you on the api primarily?
Yeah we’re on CDN :)
*content-encoding:* br
Holy crap, fastest feature request I ever saw.
Can you do draft ref draft and inline new referenced document next
😂😂😂❤️❤️❤️
Thanks y’a legend Nicolas :)
We’re starting a performance bash in 12hrs and you’re already getting wins on the board for us ❤️❤️❤️
Haha! Nice 😄 ❤️
Love to be distracted by nice shiny features 😉
🏃‍♂️💨
Well if it was that easy to speed up sanity CDN by up to a quarter I’d say it’s a pretty sweet distraction!
and it's live! Look for
*content-encoding:* br
in the response headers 😄
Nice!!! Thanks Nicholas.
Let me know if there are more infra features we can do 😉
You know it :) <3
ooooh, can we do it for SVGs too? Definitely already compressing more on the graphql CDN 🙂, a random example query i just did got 6% smaller
Also interested in what kind of perf timing diff you’re seeing. Its possible it could be a slower first call and faster subsequent calls, very interested in how it impacts your times 🙂
I added brotli for svg's too!
https://cdn.sanity.io/images/qtzcw0t9/production/11f5bbfe343cb8371f867403de78ba05a13c213b-604x640.svg?h=240&q=80&fit=max&auto=format&dpr=1
https://cdn.sanity.io/images/qtzcw0t9/production/fcfc79bf6bd24ac15a0f1e70dc3d05ed4237ba29-306x240.svg?h=240&q=80&fit=max&auto=format&dpr=1 Perf timing is negligible, this is solved when our varnish cache fetches upstream, so you're really getting an image transformation at the same time, the extra 1 ms at that point is nothing. It's stored as brottli compressed inside varnish, and transcoded to gzip if client does not support brottli.
Very cool. Seeing a range of not much to 15% smaller depending on the svg for us in prod. Thanks again Nicholas!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?