Prejsť na hlavný obsah
← 📄 HTML & the platform·Modul A7 · Lekcia 11
ÚlohaBuild a minimal HTML page that the server can compress: doctype, html, head with charset + title 'Compressed', body with three paragraphs of placeholder text.

Kompresia: gzip, brotli, čo má váš server poslať

75 XP6 min
Teória

You're not setting this in HTML — but you need to know it exists

Compression happens at the HTTP layer. The server compresses, the browser decompresses, you never see it in your code. But it's THE most important "free" performance win:

  • gzip — 1992-era, widely supported. ~70% smaller than uncompressed text.
  • brotli (br) — 2013, faster + smaller than gzip. ~80% smaller than uncompressed. All modern browsers support it.

Your stack should serve Content-Encoding: br for any text response > 1KB.

How to verify

Open DevTools → Network → look at any .html / .css / .js request → "Response Headers" tab. Look for content-encoding: br (or gzip).

If you see no content-encoding header on a text response, your server isn't compressing. That's a 4x bandwidth waste.

Defaults by host

  • Vercel — brotli on, automatic.
  • Cloudflare — brotli on, automatic.
  • Netlify — brotli on, automatic.
  • Custom Nginx — you need to install ngx_brotli module + configure (gzip is built-in).
  • Apache — mod_deflate for gzip; brotli requires mod_brotli.

What NOT to compress

  • Images (.jpg, .png, .webp) — already compressed at the file level.
  • Fonts (.woff2) — already compressed.
  • Video — already compressed.

Compressing the un-compressible WASTES CPU. Configure your server to skip these MIME types.

🔒

Zaregistruj sa a začni programovať

Teória je otvorená pre každého. Editor, živý náhľad a kontrola sa odomknú so 7-dňovou bezplatnou skúškou — karta potrebná, zruš kedykoľvek.

Registrácia — bezplatná skúška →

Prvých 10 lekcií v každej trase je zdarma. Karta nie je potrebná.

← PredchádzajúcaĎalšia lekcia →

Jeden tip k Pythonu alebo webu denne — e-mailom

Krátke, ručne písané, žiadny spam. Odhlásiť jedným klikom.