Performance & Maintenance

How to Enable Gzip Compression in Apache to Speed Up Your Site

Learn how to enable Gzip compression in Apache using mod_deflate to shrink your site's file sizes by up to 70% and dramatically improve load times.

A laptop displaying an analytics dashboard with real-time data tracking and analysis tools.

To enable Gzip compression in Apache, you only need to add a configuration block to your .htaccess file. Apache will compress text-based files (HTML, CSS, JS) before sending them to the browser, reducing their size by up to 70% without the visitor noticing a thing.

It is one of the highest-ROI performance tweaks available: ten minutes of work, immediate gains visible in PageSpeed Insights.

What Is Gzip Compression and How Does It Work?

Gzip is a data compression algorithm the server applies to text files before transferring them. The browser receives the compressed file, decompresses it in milliseconds, and renders it normally. Users never notice the process — they only notice the page loads faster.

The gains are largest for plain-text files:

  • HTML: compressed 60–80%.
  • CSS and JavaScript: compressed 60–75%.
  • TTF fonts: around 40% reduction.
  • JPEG/PNG/WebP images: already compressed — Gzip does not apply here.

In practice, a page with 500 KB of text-based resources can drop to 150–200 KB, directly improving LCP (Largest Contentful Paint) and TTFB (Time to First Byte) — two key Core Web Vitals metrics.

Explore more tips in our web performance section.

Prerequisites

  • Hosting running Apache (shared, VPS, or dedicated).
  • The mod_deflate module enabled. It comes active by default on the vast majority of shared hosting plans. If you are unsure, ask your provider.
  • Access to the .htaccess file via cPanel File Manager, FTP/SFTP, or SSH.

How to Enable Gzip with mod_deflate in .htaccess

Open the .htaccess file in your site root (public_html) and add the following block at the end, without deleting anything already there:

## Gzip Compression via mod_deflate
<IfModule mod_deflate.c>

  # Compress text output
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/json
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/atom+xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/woff
  AddOutputFilterByType DEFLATE font/woff2

  # Exclude browsers with known compression bugs
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

  # Notify proxies that output varies
  Header append Vary User-Agent env=!dont-vary

</IfModule>

Save the file. Apache applies the compression immediately on the next request.

Alternative: Enable Gzip with mod_filter

Some servers have mod_filter active instead of (or alongside) mod_deflate. Here is the equivalent block:

<IfModule mod_filter.c>
  AddOutputFilterByType DEFLATE "text/html" "text/plain" "text/css"
  AddOutputFilterByType DEFLATE "application/javascript" "application/json"
  AddOutputFilterByType DEFLATE "image/svg+xml" "font/woff2"
</IfModule>

You can include both blocks in the same .htaccess file; Apache will use whichever module is available.

How to Verify Gzip Is Active

Three quick ways to check:

1. Google PageSpeed Insights

Go to pagespeed.web.dev, analyze your URL, and look for the audit "Enable text compression." If it no longer appears under failures, Gzip is working.

2. Browser Developer Tools

  1. Open Chrome, press F12, go to the Network tab.
  2. Reload the page and click on the main HTML document.
  3. In the Size column you will see two values: transferred size (compressed) and actual size. If the first is significantly smaller, Gzip is active.
  4. In the Response Headers panel look for Content-Encoding: gzip.

3. Online Compression Tool

Services like GiftOfSpeed or Check GZIP Compression let you enter a URL and see whether the response is compressed, along with the percentage saved.

Verification Method What It Shows Account Required
PageSpeed Insights Compression audit + estimated byte savings No
DevTools (F12 → Network) Content-Encoding: gzip header per resource No
Online GZIP tool Compression percentage by URL No

Gzip vs. Brotli: Which Is Better?

Brotli is Gzip's successor, developed by Google. It compresses text files 15–25% better than Gzip. However, it requires the mod_brotli module, which is less commonly available on shared hosting plans.

  • Gzip: universal compatibility — supported by 99.9% of modern browsers and virtually all hosting environments.
  • Brotli: better compression ratios, supported by all modern browsers, but requires HTTPS and server-level configuration.

The practical recommendation: enable Gzip today. If your hosting supports Brotli, request it as an additional upgrade — the two are not mutually exclusive. Apache can serve Brotli to compatible browsers and fall back to Gzip for the rest.

If you need a team to configure and optimize your server from top to bottom, elenlace.com provides web performance optimization services with verifiable PageSpeed and Core Web Vitals results.

Key Takeaways

  • Gzip is enabled in Apache by adding the mod_deflate block to .htaccess — no root access or extra tools required.
  • Text-based files (HTML, CSS, JS) compress 60–80%, reducing load time and bandwidth usage.
  • JPEG, PNG, and WebP images are already compressed; Gzip does not affect them.
  • Verify activation with PageSpeed Insights or browser DevTools by looking for the Content-Encoding: gzip response header.
  • Brotli is a superior alternative if your hosting supports it; both can coexist on the same server.

Apply this configuration right now and check PageSpeed five minutes later — you will see the difference immediately. If you want elenlace.com to handle your site's complete performance optimization, reach out and we will prepare a free audit.

FAQ

Does Gzip change how my site looks to visitors?

No. The browser decompresses files transparently before rendering them. Visitors only notice the page loads faster; the visual content is exactly the same.

Can I enable Gzip on WordPress without editing .htaccess?

Yes. Performance plugins like WP Rocket, LiteSpeed Cache, or W3 Total Cache include a Gzip compression option that adds the necessary headers automatically. That said, the .htaccess block is the lightest solution and does not depend on any plugin.

Does Gzip consume extra server resources?

Yes, but negligibly. The CPU needed to compress a modern text file is essentially trivial compared to the bandwidth savings and perceived speed improvement. On modern shared hosting it is never a bottleneck.

What if mod_deflate is not available on my hosting?

The <IfModule mod_deflate.c> wrapper makes Apache silently ignore the block if the module is not loaded — no errors will occur. Contact your hosting provider and ask them to enable it, or consider switching to a host that includes it by default.

Useful resources

Other providers and guides worth comparing:

← All