Web HostingDecember 16, 2025 24 views

How to enable GZIP compression on cPanel

How to enable GZIP compression on cPanel

How to enable GZIP compression on cPanel

Estimated Time: 5 minutes
Difficulty: Beginner ⭐
Prerequisites: Access to cPanel
Impact: 60-80% reduction in file size


📋 Introduction

GZIP compression is a technique that significantly reduces the size of files sent by your web server to your visitors' browsers. It is one of the simplest and most effective optimizations to speed up your website.

How does it work?

Without GZIP:
Server ──────────────────────────────────> Browser
         HTML File: 100 KB (original size)

With GZIP:
Server ─────────> Browser
         30 KB     (automatically decompressed)
         ↓
         100 KB (original file reconstructed)

The server compresses the files before sending them, and the browser automatically decompresses them. The process is transparent to the user.


🚀 Advantages of GZIP Compression

Performance Gains

Metric Improvement
📉 File Size Reduction 60% to 80%
Loading Time Up to 50% faster
📊 Bandwidth Significantly reduced
🔍 PageSpeed Score Noticeable improvement
📱 Mobile Experience Better (less data)

Concrete Example of Compression

File Type Original Size Compressed Size Reduction
HTML 100 KB 25 KB 75%
CSS 80 KB 18 KB 78%
JavaScript 150 KB 45 KB 70%
JSON/XML 50 KB 12 KB 76%
Fonts (SVG) 40 KB 15 KB 63%

💡 Real Example: A typical 500 KB WordPress page can be reduced to about 150 KB with GZIP, resulting in a 70% reduction!


📂 Types of Files to Compress

✅ Files to Compress (text)

Type Extensions MIME Type
HTML .html, .htm text/html
CSS .css text/css
JavaScript .js application/javascript
JSON .json application/json
XML .xml application/xml
Text .txt text/plain
SVG .svg image/svg+xml
Fonts .ttf, .otf font/ttf, font/otf
WOFF .woff font/woff

❌ Files Not to Compress

Type Reason
Images (JPEG, PNG, GIF, WebP) Already compressed
Videos (MP4, WebM) Already compressed
Audio (MP3, OGG) Already compressed
PDF Already compressed
Archives (ZIP, RAR, GZ) Already compressed

⚠️ Important: Compressing already compressed files can increase their size and unnecessarily slow down the server.


⚙️ Method 1: Optimize Website (Recommended)

This is the simplest method, directly integrated into cPanel.

Step 1: Access the Tool

  1. Log in to cPanel
  2. In the Software section, click on Optimize Website
    Image

💡 Tip: Use the cPanel search bar and type "optimize" to quickly find the tool.


Step 2: Choose the Compression Type

The interface presents 3 options:

Option Description Recommendation
Disabled Compression disabled ❌ Not recommended
Compress All Content Compresses all content Recommended
Compress the specified MIME types Compresses only specified types ⚠️ Advanced

Step 3: Enable Compression

For most sites:

  1. Select "Compress All Content"
  2. Click on "Update Settings"

ImageConfirmation message:

✅ Website optimization preferences updated.
Content compression is now enabled.
Content compression is now enabled for all content.

Image

Advanced Option: Specific MIME Types

If you prefer precise control:

  1. Select "Compress the specified MIME types"
  2. Enter the MIME types to compress:
text/html text/plain text/xml text/css text/javascript 
application/javascript application/x-javascript application/xml 
application/json application/rss+xml application/xhtml+xml
image/svg+xml font/ttf font/otf font/woff font/woff2
  1. Click on "Update Settings"

📝 Method 2: Via .htaccess

If the "Optimize Website" tool is not available or for finer control.

Step 1: Access the .htaccess File

  1. In cPanel, open the File Manager
  2. Go to the public_html folder
  3. Click on Settings in the top right
  4. ✅ Check "Show hidden files (dotfiles)"
  5. Locate and edit the .htaccess file

Step 2: Add the Compression Code

Add this code at the beginning of the .htaccess file:

# =============================================
# GZIP COMPRESSION
# =============================================
<IfModule mod_deflate.c>
    # Compress HTML, CSS, JavaScript, Text, XML, and fonts
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/atom+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/ld+json
    AddOutputFilterByType DEFLATE application/manifest+json
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/x-font-truetype
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/opentype
    AddOutputFilterByType DEFLATE font/woff
    AddOutputFilterByType DEFLATE font/woff2
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE image/x-icon
    
    # Old browser compatibility
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    
    # Do not compress images (already compressed)
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|webp)$ no-gzip
    
    # Vary header for proxies
    Header append Vary User-Agent env=!dont-vary
</IfModule>
# =============================================
# END GZIP COMPRESSION
# =============================================

Minimal Simplified Code

If you prefer a shorter version:

# GZIP COMPRESSION (simple version)
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
    AddOutputFilterByType DEFLATE text/javascript application/javascript
    AddOutputFilterByType DEFLATE application/xml application/json
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

Step 3: Save

  1. Click on Save Changes
  2. Test your site to ensure it works correctly

🔧 Method 3: Via WordPress Plugin

For WordPress sites, some cache plugins automatically enable GZIP.

Plugins with Built-in GZIP Compression

Plugin Free GZIP Configuration
WP Rocket ❌ Paid Automatic
LiteSpeed Cache ✅ Free Automatic (LiteSpeed servers)
W3 Total Cache ✅ Free Performance → Enable HTTP compression
WP Super Cache ✅ Free Advanced → Compress pages
WP Fastest Cache ✅ Free Options → Gzip
Autoptimize ✅ Free Not included (only minification)

Example: Enable GZIP with WP Super Cache

  1. Install and activate WP Super Cache
  2. Go to Settings → WP Super Cache
  3. Tab Advanced
  4. ✅ Check "Compress pages so they're served more quickly to visitors"
  5. Click on Update Status

Example: Enable GZIP with W3 Total Cache

  1. Install and activate W3 Total Cache
  2. Go to Performance → General Settings
  3. In the Browser Cache section
  4. ✅ Check "Enable HTTP (gzip) compression"
  5. Click on Save all settings

✅ Check if GZIP is Enabled

Method 1: Online Tools

Use these free tools to check compression:

Tool URL Advantage
GiftOfSpeed giftofspeed.com/gzip-test Simple and fast
CheckGzipCompression checkgzipcompression.com Detailed
GTmetrix gtmetrix.com Comprehensive analysis
PageSpeed Insights pagespeed.web.dev Official Google tool
KeyCDN Tools tools.keycdn.com/http2-test Multi-tests

Method 2: Browser (DevTools)

  1. Open your site in Chrome or Firefox
  2. Press F12 to open DevTools
  3. Go to the Network tab
  4. Reload the page (F5)
  5. Click on a file (e.g., the main HTML document)
  6. In the Headers tab, look for:
Content-Encoding: gzip

If you see Content-Encoding: gzip → Compression is active ✅


Method 3: Command Line (curl)

curl -I -H "Accept-Encoding: gzip,deflate" https://your-site.com

Look for in the response:

Content-Encoding: gzip

📊 Compare Before/After

Using GTmetrix

  1. Go to gtmetrix.com
  2. Test your URL before enabling GZIP
  3. Note the page weight and loading time
  4. Enable GZIP
  5. Test again
  6. Compare the results

Result Example

Metric Before GZIP After GZIP Improvement
Total weight 2.5 MB 850 KB -66%
Loading time 4.2s 2.1s -50%
Performance Score 72/100 89/100 +17 points

🔧 Troubleshooting

GZIP Not Working

❌ Issue ✅ Solution
mod_deflate module not installed Contact the host to enable it
.htaccess code ignored Ensure AllowOverride is enabled
Incompatible PHP Handler CGI/FastCGI may require different config
CDN disables compression Enable GZIP in CDN settings
Browser cache Clear cache and test in incognito mode

500 Error after .htaccess Modification

  1. Using FTP or File Manager :

    • Edit the .htaccess file
    • Remove the added GZIP code
    • Save
  2. mod_deflate module not available :

    • The code <IfModule mod_deflate.c> should prevent the error
    • Contact the host to check the availability of the module

    Active GZIP but not on all files

    Check these points:

    1. Missing MIME Types: Add missing types to the .htaccess code
    2. Cache Plugin: Some plugins serve static files without GZIP
    3. CDN: Files served by the CDN may not be compressed
    4. External Resources: Files hosted elsewhere are not under your control

    Conflict with other .htaccess rules

    Place the GZIP code at the beginning of the .htaccess file, before the WordPress rules:

    # GZIP COMPRESSION (place first)
    <IfModule mod_deflate.c>
        # ... compression code ...
    </IfModule>
    
    # BEGIN WordPress
    # ... WordPress rules ...
    # END WordPress
    

    ⚡ GZIP vs Brotli

    Brotli is a newer compression algorithm, offering better performance.

    Comparison

    Criterion GZIP Brotli
    Compression ~70% ~75-80%
    Browser Support 99%+ 96%+
    Compression Speed Fast Slower
    Decompression Speed Fast Fast
    Server Support Universal Modern

    Enable Brotli (if available)

    # BROTLI COMPRESSION (if mod_brotli available)
    <IfModule mod_brotli.c>
        AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml
        AddOutputFilterByType BROTLI_COMPRESS text/css text/javascript
        AddOutputFilterByType BROTLI_COMPRESS application/javascript application/json
        AddOutputFilterByType BROTLI_COMPRESS image/svg+xml
    </IfModule>
    

    💡 Most shared hosting uses GZIP. Brotli is more common on VPS/dedicated and CDNs like Cloudflare.


    🎯 Best Practices

    Combine GZIP with other optimizations

    Optimization Impact Priority
    GZIP Compression -70% file size 🔴 High
    Minify CSS/JS -10-30% additional 🟠 Medium
    Browser Cache Avoid re-downloads 🔴 High
    Optimize Images -50-80% image size 🔴 High
    CDN Reduce latency 🟠 Medium
    HTTP/2 Multiplex connections 🟢 Bonus

    Complete .htaccess Code (GZIP + Cache)

    # =============================================
    # GZIP COMPRESSION
    # =============================================
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/html text/plain text/xml
        AddOutputFilterByType DEFLATE text/css text/javascript
        AddOutputFilterByType DEFLATE application/xml application/xhtml+xml
        AddOutputFilterByType DEFLATE application/rss+xml application/atom+xml
        AddOutputFilterByType DEFLATE application/javascript application/x-javascript
        AddOutputFilterByType DEFLATE application/json application/ld+json
        AddOutputFilterByType DEFLATE image/svg+xml image/x-icon
        AddOutputFilterByType DEFLATE font/ttf font/otf font/woff font/woff2
    </IfModule>
    
    # =============================================
    # BROWSER CACHE
    # =============================================
    <IfModule mod_expires.c>
        ExpiresActive On
        
        # Images
        ExpiresByType image/jpeg "access plus 1 year"
        ExpiresByType image/png "access plus 1 year"
        ExpiresByType image/gif "access plus 1 year"
        ExpiresByType image/webp "access plus 1 year"
        ExpiresByType image/svg+xml "access plus 1 year"
        ExpiresByType image/x-icon "access plus 1 year"
        
        # Fonts
        ExpiresByType font/ttf "access plus 1 year"
        ExpiresByType font/otf "access plus 1 year"
        ExpiresByType font/woff "access plus 1 year"
        ExpiresByType font/woff2 "access plus 1 year"
        
        # CSS and JavaScript
        ExpiresByType text/css "access plus 1 month"
        ExpiresByType application/javascript "access plus 1 month"
        
        # HTML
        ExpiresByType text/html "access plus 0 seconds"
    </IfModule>
    
    # =============================================
    # SECURITY AND PERFORMANCE HEADERS
    # =============================================
    <IfModule mod_headers.c>
        # Vary header for proxies
        Header append Vary Accept-Encoding
        
        # Keep-Alive
        Header set Connection keep-alive
    </IfModule>
    

    📝 Summary

    ENABLE GZIP COMPRESSION:
    
    METHOD 1 - Optimize Website (Recommended):
    1. cPanel → Software → Optimize Website
    2. Select "Compress All Content"
    3. Click on "Update Settings"
    4. Done! ✅
    
    METHOD 2 - .htaccess:
    1. Open File Manager
    2. Edit .htaccess in public_html
    3. Add compression code
    4. Save
    
    METHOD 3 - WordPress Plugin:
    └── WP Super Cache, W3 Total Cache, WP Fastest Cache...
    
    CHECK ACTIVATION:
    ├── giftofspeed.com/gzip-test
    ├── gtmetrix.com
    ├── DevTools → Network → Headers
    └── Look for "Content-Encoding: gzip"
    
    TYPES TO COMPRESS:
    ├── ✅ HTML, CSS, JavaScript, JSON, XML
    ├── ✅ Fonts (TTF, OTF, WOFF, WOFF2)
    ├── ✅ SVG, text
    └── ❌ Images, videos, PDF (already compressed)
    
    EXPECTED BENEFITS:
    ├── 📉 Size reduction: 60-80%
    ├── ⚡ Loading: up to 50% faster
    └── 📊 PageSpeed Score: +10-20 points