Compress Components with Gzip: Fix the Warning on Apache and cPanel
Speed tests such as GTmetrix show "Compress components with gzip" when your server sends text files, like your pages, stylesheets and scripts, without compressing them first. Compressed text often travels at less than half its original size, so pages arrive sooner, especially on mobile connections.
This guide covers Apache and LiteSpeed servers, which run most shared and cPanel hosting. If your host uses Nginx, see the note near the end.
What should be compressed, and what should not
Text-based files shrink a lot when compressed:
- Pages (HTML)
- Stylesheets (CSS) and scripts (JavaScript)
- Data files such as JSON and XML
- SVG images and favicon (.ico) files
Some files are already compressed, and compressing them again only wastes server time:
- Photos and images in JPEG, PNG, WebP or GIF format
- WOFF and WOFF2 web fonts
- ZIP files and videos
Step 1: Check whether compression is already on
Before changing anything, check what your server sends now.
- Open your website in Chrome or Firefox and press F12 to open the developer tools.
- Open the Network tab and reload the page.
- Click the first request (your page) and look under Response Headers.
- Look for
content-encoding: gzip. If you seecontent-encoding: brinstead, your server uses Brotli, which compresses even better and also clears the warning.
If the header is there, that file is already compressed. Check a CSS file in the same list too, since servers sometimes compress pages but not stylesheets.
You can also check from a terminal:
curl -s -o /dev/null -D - -H "Accept-Encoding: gzip" https://example.com/
Replace the address with your own page and look for the content-encoding line in the output.
Step 2: Turn compression on
The easy way on cPanel
In cPanel, open Software, then Optimize Website, choose "Compress All Content" and press Update Settings. cPanel writes the compression rules for you.
The manual way with .htaccess
Open the .htaccess file in your website's main folder (usually public_html). In cPanel's File Manager, open Settings and tick "Show Hidden Files" if you cannot see it. Download a copy as a backup first.
Add these lines near the top:
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/json application/ld+json application/xml application/rss+xml
AddOutputFilterByType DEFLATE image/svg+xml image/x-icon font/ttf font/otf
</IfModule>
</IfModule>
The two IfModule lines matter. On Apache 2.4 the AddOutputFilterByType command needs a server module called mod_filter. If your host has not enabled it, a bare rule makes the whole site show a 500 error. Wrapped like this, the rules are simply skipped instead.
LiteSpeed servers read the same rules. Many LiteSpeed hosts also compress by default, so check Step 1 before adding anything.
Step 3: Test again
Repeat Step 1 and confirm content-encoding now appears for your page and your CSS. Then run the speed test again. Some tools show the previous result for a while, so start a fresh test rather than reloading an old report.
Why the warning can stay
- Compression is not available on your hosting. If mod_deflate is not enabled, the wrapped rules quietly do nothing. Ask your host to enable it, or use cPanel's Optimize Website option.
- The rules are in the wrong place. They must be in the
.htaccessfile in your site's main folder, named exactly.htaccess, nothtaccess.txt. - The files are not yours. If the warning lists files from other websites, such as analytics, chat widgets or ad scripts, only their owners can compress them.
- A CDN or proxy sits in front of your site. With Cloudflare, for example, compression happens on Cloudflare's side, so check the headers your visitors actually receive rather than your server's settings.
- Two systems compress the same page. If a caching plugin or PHP setting also compresses output, pages can arrive as unreadable characters. Keep one method only.
- Your server runs Nginx. Nginx ignores
.htaccessfiles. Compression is switched on in the server's own configuration (thegzip on;setting), so ask your host.
Still seeing the warning?
If compression will not switch on, or your site shows an error after editing .htaccess, we can fix it for you as part of our PHP and website fix service.