How to enable GZIP compression on cPanel
GZIP compression shrinks the text files the server sends to visitors, so pages load faster. This guide shows how to enable GZIP compression on cPanel with the Optimize Website tool, or through the .htaccess file. It then explains how to check that it works.
How GZIP compression works
The server compresses each text file before sending it. The browser decompresses it straight away, with nothing asked of the visitor. The saving depends on the content. It is large on text and zero on files that are already compressed.
| Compress | MIME types |
|---|---|
| HTML and text | text/html, text/plain |
| CSS | text/css |
| JavaScript | application/javascript, text/javascript |
| JSON and XML | application/json, application/xml, text/xml |
| SVG | image/svg+xml |
| TTF and OTF fonts | font/ttf, font/otf |
There is no point compressing JPEG, PNG, GIF or WebP images, video, audio, PDF files, ZIP archives or WOFF and WOFF2 fonts. These formats are already compressed. Compressing them again gains nothing and keeps the server busy.
Enable GZIP in Optimize Website
This is the recommended method. It sets compression for the whole account, without touching your site's files.
On your hosting page, click Advanced panel at the top right. cPanel opens straight away, with no login details to type.
In the Software section, click Optimize Website. You can also type "optimize" in the cPanel search bar.
Under Compress Content, choose Compress All Content.
Click Update Settings.
cPanel confirms that content compression is now enabled for all content. The change applies straight away.

| Choice | Effect |
|---|---|
| Disabled | no compression |
| Compress All Content | Apache compresses everything it sends, the recommended setting |
| Compress the specified MIME types. | only the types listed in MIME Types are compressed |
This setting applies to Apache (the mod_deflate module). Compression done by PHP itself (zlib.output_compression) is set separately, in the MultiPHP INI Editor. The guide How to modify PHP settings (php.ini) on cPanel explains it. Turn on one or the other, not both.
Compress only some types
Choose Compress the specified MIME types., then enter the types in MIME Types, separated by spaces.
text/html text/plain text/xml text/css text/javascript
application/javascript application/xml application/json
application/rss+xml application/xhtml+xml image/svg+xml font/ttf font/otf
Enable GZIP through the .htaccess file
The .htaccess file lets you choose the compressed types yourself, or keep this setting with your site's files.
In cPanel, open the File Manager in the Files section, then the
public_htmlfolder.In the file manager's settings, show hidden files. The
.htaccessfile starts with a dot.Download a copy of the file, then open it for editing.
Add the block below at the top of the file, then save.
# GZIP compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/json application/ld+json application/manifest+json
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml image/x-icon
AddOutputFilterByType DEFLATE font/ttf font/otf application/vnd.ms-fontobject
</IfModule>
The <IfModule mod_deflate.c> tag protects the site. If the module were missing, Apache would ignore the block instead of showing an error. Then open your site to check that it displays normally.
On a WordPress site, place the block before the WordPress rules.
# GZIP compression, first
<IfModule mod_deflate.c>
# ... compression rules ...
</IfModule>
# BEGIN WordPress
# ... WordPress rules ...
# END WordPress
Enable GZIP with a WordPress plugin
Several cache plugins, such as WP Super Cache, W3 Total Cache or WP Fastest Cache, offer a compression option. It usually adds rules to the .htaccess file. If compression is already on in Optimize Website, leave this option off.
Check if GZIP is enabled
In the browser
Open your site in Chrome, Edge or Firefox, then the developer tools with the
F12key.Open the Network tab and reload the page.
Click the HTML document at the top of the list, then look at its response headers.
The line Content-Encoding: gzip shows that compression is on. Behind a CDN, the value can be br (Brotli), which is just as good.
On the command line
curl -I -H "Accept-Encoding: gzip" https://mysite.com
Look for this line in the response.
Content-Encoding: gzip
With an online tool
The GiftOfSpeed GZIP test tells you whether a URL is compressed. PageSpeed Insights flags text files sent without compression, the issue it calls enabling text compression. To measure the effect on your site, compare the page's transferred size before and after.
Fix common problems
Compression does not show up
Check the choice saved in Optimize Website.
Clear the browser cache, or test in a private window.
Clear your WordPress plugin's cache, which may still serve old pages.
If the site runs through a CDN, check compression in its settings.
Files loaded from another site (fonts, external scripts) do not depend on your hosting.
Error 500 after editing .htaccess
A line in the file is wrong. Open .htaccess in the File Manager or over FTP, remove the block you added, then save. You can also restore the copy you downloaded before editing.
Some types are not compressed
With the MIME type choice or with an .htaccess block, only the listed types are compressed. Add the missing type to the list. A file's type appears in the Content-Type header of the response.
GZIP or Brotli
Brotli is a newer algorithm that compresses text a little better than GZIP. Current browsers support both. CDNs such as Cloudflare often apply it on their own. On the hosting, the method to use remains GZIP through Optimize Website.
This block only takes effect if the server loads the mod_brotli module. Otherwise, Apache ignores it.
# Brotli compression, if mod_brotli is 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>
Add browser caching
Compression makes each transfer lighter. Browser caching avoids sending again the files that have not changed. The two work together, as in this .htaccess block.
# 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
</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>
With a long cache, a changed CSS or JavaScript file can stay outdated for your visitors. Rename it or add a version number to its URL, as most CMSs do.
Need help?
Open a ticket from Tickets › Open a ticket (dash.ouiheberg.com/tickets/new), or click the Contact support tile at the bottom of your hosting page. You can also ask your question on our Discord.
cPanel hosting with email accounts and databases, managed from the OuiHeberg client area.
View plans →