Text files such as HTML, CSS, JavaScript, JSON and SVG compress very well, often to a quarter of their size. Sending them compressed makes pages load faster, especially on mobile. cPanel's Optimize Website tool turns server compression on for your whole account with one setting.
Before you start
- Check whether compression is already active (it often is on LiteSpeed servers or through a cache plugin). See Check that it works below.
- Images (JPG, PNG, WebP) and videos are already compressed; compressing them again gains nothing.
Enable compression
- Open cPanel → Software → Optimize Website.
- Choose one option:
- Disabled: no compression.
- Compress All Content: compress every response. Simple, and the server skips types that do not benefit on most setups.
- Compress the specified MIME types: list types separated by spaces.
- For the second approach, a good list is:
text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml image/svg+xml - Click Update Settings.
cPanel writes the rules into public_html/.htaccess, so they apply to the primary domain and folders below it. Addon domains with their own document root outside public_html may need the same rules in their own .htaccess.
Check that it works
- In the browser, open developer tools (F12) → Network, reload, click the page request and look for
content-encoding: gziporbrin the response headers. - From a terminal:
curl -sI -H "Accept-Encoding: gzip, br" https://example.com/ | grep -i content-encoding
An answer of br means Brotli, which is even better than gzip; LiteSpeed servers can serve it automatically.
Tip: If your cache plugin (for example LiteSpeed Cache) already enables compression or Brotli, leave Optimize Website disabled to avoid duplicate rules. One source of compression is enough.
Compression is only one part of speed
For a noticeably faster site, combine compression with page caching, optimised images and a current PHP version. See why is my website slow? and LiteSpeed page optimisation.
Troubleshooting
- Garbled characters or a download prompt: content is compressed twice (by a PHP app and the server). Disable compression in the app or in Optimize Website.
- 500 error after saving: the
.htaccesshas a conflict; restore a backup of the file or see fix 500 errors. - No content-encoding header: a CDN in front of the site may compress or strip it; check the CDN settings.
