Aller au contenu principal
← 📄 HTML & the platform·Module A7 · Leçon 11
TâcheBuild a minimal HTML page that the server can compress: doctype, html, head with charset + title 'Compressed', body with three paragraphs of placeholder text.

Compression : gzip, brotli, ce que votre serveur doit envoyer

75 XP6 min
Théorie

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.

🔒

Inscris-toi pour coder

La théorie est ouverte à tous. L'éditeur, l'aperçu live et le check se débloquent avec un essai gratuit de 7 jours — carte requise, annulable à tout moment.

S'inscrire — essai gratuit →

Les 10 premières leçons de chaque parcours sont gratuites. Pas de carte requise.

← PrécédentLeçon suivante →

Recevez une astuce Python ou web par jour — par email

Court, écrit à la main, sans spam. Désabonnement en un clic.