Steric
Steric

Reputation: 415

Data compression libraries: brotli vs zlib

Which data compression works best for compressing javascript files when downloaded from any website: brotli or zlib ?

Upvotes: 0

Views: 2713

Answers (1)

Mark Adler
Mark Adler

Reputation: 112374

I'll assume that by "javascript files" you mean javascript source code.

brotli (content encoding "br") is better for non-dynamic content, where you expect it to be compressed once, but transmitted and decompressed many times. That would normally be the case for javascript. The average gain is about 20% for javascript code.

Not all clients accept brotli (so far Firefox, Chrome, and Edge do). If the client doesn't accept it, then the encoding negotiation will automatically fall back to content encoding gzip (what zlib produces).

Upvotes: 3

Related Questions