Performance & Maintenance

How to Enable GZIP Compression in Apache and cPanel

Learn how to enable GZIP compression in Apache and cPanel in minutes to shrink your site's transfer size by up to 70 % and dramatically speed up load times.

A digital tablet showing a web analytics dashboard with graphs and charts.

To enable GZIP on Apache, add a few lines to your site's .htaccess file using the mod_deflate module — or, if you're on cPanel, turn it on from the panel without touching any code. Either way, you'll immediately serve lighter pages, cut load times, and earn a better score in Google PageSpeed Insights.

What is GZIP Compression and Why Does It Matter?

GZIP is a compression algorithm that the server applies to files before sending them to the browser. The browser decompresses them on the fly, so visitors see the exact same page — just transferred with far less data.

The benefits are real and measurable:

  • HTML, CSS, and JavaScript typically compress by 60–70 % of their original size.
  • Lower bandwidth consumption on your hosting plan.
  • Faster pages on slow connections and mobile networks.
  • A positive SEO signal, since Google rewards page speed.

Every modern browser and the vast majority of shared Apache hosting servers support GZIP out of the box — it just needs to be switched on.

Method 1: Enable GZIP from cPanel (No Code Required)

If your hosting runs cPanel, this is the fastest path:

  1. Log in to your cPanel account.
  2. Under the Software section, click Optimize Website.
  3. Select Compress All Content, or manually choose the MIME types you want to compress.
  4. Click Update Settings.

cPanel automatically writes the required directives to your .htaccess file. You don't need to do anything else.

Method 2: Enable GZIP via .htaccess and mod_deflate

If you want full control, or the cPanel option isn't available, open the .htaccess file in your site's root directory and add the following block:

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
</IfModule>

Save the file and reload your site. Apache will start compressing responses immediately.

What About mod_gzip?

mod_gzip is the older module from Apache 1.x days. On any modern Apache 2.x installation — which covers virtually all current shared hosting — mod_deflate is the correct module to use. If you see references to mod_gzip in old tutorials, skip them.

How to Verify GZIP Is Working

After enabling it, confirm it's active using one of these methods:

  • curl from the terminal: curl -H "Accept-Encoding: gzip" -I https://yourdomain.com — look for the Content-Encoding: gzip header in the response.
  • Chrome DevTools: open the Network tab, reload the page, click any text resource, and check the response headers.
  • GiftOfSpeed or GTmetrix: free tools that visually confirm GZIP status in seconds.

If the Content-Encoding: gzip header appears, compression is live. If not, verify that the .htaccess file is in the correct root directory and that mod_deflate is enabled on your server.

File Types You Should NOT Compress

Leave JPEG, PNG, WebP, GIF, ZIP, PDF, and video files out of your compression list. These formats are already compressed; running them through GZIP adds CPU overhead without meaningfully reducing their size.

Compressing only text-based assets (HTML, CSS, JS, SVG, XML) is the correct approach — and the one recommended by performance-focused web agencies like elenlace.com.

Key Takeaways

  • GZIP compresses text-based resources by 60–70 %, reducing load times and bandwidth usage.
  • On cPanel you can enable it in two clicks via Optimize Website.
  • The manual method is adding a <IfModule mod_deflate.c> block to your .htaccess.
  • Always verify that the Content-Encoding: gzip response header is present after enabling it.
  • Do not compress already-compressed files like images or binaries.

Enabling GZIP is one of the easiest, highest-impact performance wins you can make today. If you'd like a full site speed audit, the team at elenlace.com can pinpoint every bottleneck holding your site back. Find more techniques in our web performance guide.

FAQ

Does GZIP affect my site's SEO?

Yes, positively. Google uses page speed as a ranking factor. By reducing the size of your pages, GZIP helps them load faster, which can improve your position in search results.

Do I need to restart Apache after editing .htaccess?

No. Changes to .htaccess take effect immediately — no server restart needed. Just save the file and reload your site in the browser.

Can I enable GZIP on WordPress?

Absolutely. WordPress runs on Apache in most shared hosting environments, so the .htaccess method works directly. Caching plugins like W3 Total Cache or LiteSpeed Cache also include a built-in GZIP compression option in their settings.

Is GZIP the same as Brotli?

No. Brotli is a newer compression algorithm from Google that delivers 15–20 % better compression than GZIP. However, it requires HTTPS and is not always available on shared hosting. GZIP remains the universal, most compatible standard.

Compare providers

Other providers and guides worth comparing:

← All