Account

Guides

How to enable gzip and brotli compression

You can turn on gzip in cPanel under Optimize Website or with mod_deflate rules in .htaccess, and brotli through a cache plugin or panel option on LiteSpeed hosting, or with mod_brotli on Apache. Compression shrinks your HTML, CSS and JavaScript on the server, so pages load faster and use less bandwidth. Turn it on as soon as a speed test shows a heavy page or no Content-Encoding header.

Check your site

>
  1. Enable compression in cPanel

    In cPanel, open Optimize Website in the Software section and choose Compress All Content. This turns on gzip for text responses without editing any files.

  2. Add gzip rules to .htaccess

    If the panel has no such option, open .htaccess in your site root through File Manager and add a mod_deflate block with AddOutputFilterByType DEFLATE lines for text/html, text/css, application/javascript and application/json.

  3. Enable brotli if the server supports it

    Brotli compresses text more tightly than gzip. On LiteSpeed hosting, a cache plugin or a panel option turns it on. On Apache you need mod_brotli and an AddOutputFilterByType BROTLI_COMPRESS directive.

  4. Compress text types only

    Include html, css, js, json, xml, svg and the font formats ttf, otf and eot in the rules (woff and woff2 are already compressed). Leave out images such as jpg, png and webp: they are already compressed, and compressing them again only wastes CPU.

  5. Clear the cache and reload

    After the change, clear the site cache (in WordPress, through the cache plugin) and the browser cache, so the server sends back the newly compressed page.

How to verify the result

Run the SpoofLens speed test again. The response should now carry Content-Encoding: gzip or br, and the page size should drop noticeably.

Tip: Keep compression in one place: Optimize Website writes its rules into .htaccess, so do not add a second set by hand. Garbled pages usually mean PHP compresses the output (zlib.output_compression) on top of the server.

Related guides