Content encoding

None of the encodings listed are involved with patent concerns.

Usage Encoding Extension
Rasterized image JPEG XL .jxl
WebP .webp
Vector image SVG .svg
Lossy audio Opus .opus
Vorbis .ogg
AAC-LC .m4a .aac
Lossless audio WavPack .wv
FLAC .flac
Web compression Brotli .br
gzip .gz
Bundle compression xz .xz .txz
bzip2 .bz2 .tbz2
lzip .lz .tlz
Font WOFF2 .woff2

Read below for further details.

Rasterized image encoding

Lossy

As WebP is properly supported in every browser built for systems newer than Windows XP, and it offers better quality-to-size ratio than all JPEG encoders, it is considered the best fallback format. However, as JPEG XL exists as an all-around better universal image format, lossy images should also be encoded with JPEG XL whenever possible.

Compared to all other image formats, JPEG XL offers jawdropping image fidelity, unmatched quality-to-size ratio, proper progressive loading and better responsiveness. The cherry on top of JPEG XL would be its ability to losslessly transcode from existing JPEG files, offering about 20% size reduction with cheap JPEG lossless bitstream reconstruction, which paves its way to be a backwards-compatible drop-in replacement for image storage and distribution.

MozJPEG-fronted JPEG XL encoding hasn't been tested yet.

Codec Use Params
JPEG XL Delivery cjxl -d 2.2 -e 4 -p
Archival cjxl -d 1.1 -e 4 -p
WebP Delivery cwebp -m 5 -psnr 56
Archival cwebp -m 5 -q 99

The full feature set comparison chart is available on Cloudinary.

Battle of the image codecs!

Lossless

WebP Lossless should always be offered when lossless image codecs are required. JPEG XL Lossless should only be offered alongside when it proves to be smaller than WebP in a case-by-case scenario.

Audio encoding

Lossy

When high sampling rates are required, choose Vorbis. When support for the Apple ecosystem is required, choose AAC-LC. Otherwise use Opus under all possible scenarios, but beware that Opus only supports sampling at 48kHz.

Below are the suggested bitrates under different scenarios, when encoding stereo audio content under either 44.1kHz or 48kHz. Audio content should be encoded with constrained variable bitrate (CVBR).

The AAC-LC encoder in question is libfdk_aac, being the best FOSS AAC-LC encoder out there. The only AAC-LC encoder better than libfdk_aac is Apple's Audio Toolbox, which is proprietary and not in consideration.

CodecBasicStreamBalancedGenericQuality
Opus96kbps144kbps160kbps192kbps256kbps
Vorbis128kbps160kbps192kbps224kbps320kbps
AAC-LC128kbps160kbps192kbps224kbps320kbps

Keep in mind that the scenario under "basic" indicates that, all audio content encoded with provided parameters should be virtually undistinguishable from LAME-encoded MP3 files at 192kbps.

Lossless

Streaming lossless audio is generally considered a bad idea.

When web support isn't planned, or the target platforms aren't severely underpowered, WavPack is the recommended codec for storing lossless audio. Recommended encoding parameters for the official CLI util: wavpack -hhvx -x 3

Compression

Web

Brotli should be preferred over gzip at all times. Static low-entropy content (e.g. plain text files) should always be pre-compressed, with or without the original uncompressed file available.

For static precompression, the original file can be omitted when the space is constrained, serving only precompressed blobs. When compatibility with other infrastructure isn't in consideration, precompressed gzip files can also be omitted, although it's not recommended in most cases.

Algorithm Use Params
Brotli Real-time brotli -4
Precompression brotli -q 11
gzip Real-time gzip -4
Precompression zopfli --i25

Bundle

bzip2 should be the default bundle compression algorithm, unless either lzip or xz is proven to be better in a case-by-case scenario. Quality should always set to 9, unless a lower quality value is proven to yield a better result for smaller files.

Due to platform differences, xz should be avoided for automation scripts that may install compression algorithms on the fly.

Font

As practically all modern browsers support the WOFF2 font format, all required TrueType and OpenType fonts must be served as WOFF2 files instead. If for unspecified reasons that original files must be served, always consider precompression and avoid storing uncompressed files.