Sari la conținutul principal
← 📄 HTML & the platform·Modul A7 · Lecția 11
SarcinăBuild a minimal HTML page that the server can compress: doctype, html, head with charset + title 'Compressed', body with three paragraphs of placeholder text.

Compresie: gzip, brotli, ce ar trebui să trimită serverul tău

75 XP6 min
Teorie

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.

🔒

Înregistrează-te pentru a începe să programezi

Teoria e accesibilă tuturor. Editorul, previzualizarea live și verificarea se deblochează cu o probă gratuită de 7 zile — card necesar, anulabilă oricând.

Înregistrare — probă gratuită →

Primele 10 lecții din fiecare traseu sunt gratis. Fără card.

← AnterioarăLecția următoare →

Primește un sfat Python sau web pe zi — prin email

Scurt, scris de mână, fără spam. Dezabonare cu un click.