Caching & Compression in Apache

From the Apache cheat sheet ยท Modules & Performance ยท verified Jul 2026

Caching & Compression

Enable GZIP compression and browser caching for performance

apacheconf
# Enable compression (mod_deflate)
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css
    AddOutputFilterByType DEFLATE application/javascript application/json
</IfModule>

# Browser caching (mod_expires)
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
</IfModule>
๐Ÿ’ก GZIP compression reduces text-based response sizes by 60-80% โ€” enable it on every server
โšก Set "access plus 1 year" for static assets with fingerprinted filenames (style.a1b2c3.css)
๐Ÿ“Œ HTML should have Cache-Control: no-cache so users always get the latest content
๐ŸŸข Use immutable with long max-age for hashed/fingerprinted assets โ€” browsers skip revalidation
cachingcompressiongzipperformance

More Apache tasks

Back to the full Apache cheat sheet