Skip to content
General

How to Enable GZIP Compression on Your Website

GZIP compression shrinks HTML, CSS and JavaScript before they are sent, so pages load faster. Here is how to check it and enable it in cPanel, Apache and Nginx.

By Tremhost Experts Updated November 5, 2026 4 min read

To enable GZIP compression, first test whether your site already sends compressed files, because many hosts turn it on at server level. If it is off, enable it in cPanel’s Optimize Website tool, with mod_deflate rules in .htaccess on Apache, or with the gzip directives in your Nginx configuration. Then test again to confirm the Content-Encoding: gzip header appears.

What GZIP compression is

GZIP is a file compression format. When a browser requests a page, it tells the server which compression formats it accepts, using the Accept-Encoding header. If the server supports GZIP, it compresses text files such as HTML, CSS and JavaScript before sending them and adds a Content-Encoding: gzip header. The browser decompresses them automatically. Visitors see no difference except that the page arrives sooner.

Text compresses very well, because it contains a lot of repetition. HTML, CSS, JavaScript, JSON, XML and SVG files often shrink to a fraction of their original size. Images such as JPEG, PNG and WebP, and video files, are already compressed, so GZIP gains little on them and wastes CPU time.

Why it matters

  • Faster pages. Smaller files take less time to download, which matters most on slower mobile connections.
  • Less data used. Your visitors use less mobile data, and your hosting bandwidth goes further.
  • Better page speed scores. Tools such as Google PageSpeed Insights flag text that is sent without compression.

Compression is one part of performance. Caching, image optimisation and a lean theme also matter.

Step 1: Check whether compression is already on

Do this before changing anything. Many servers, including LiteSpeed and most managed hosts, already compress text files.

  1. Open your site in Chrome, Edge or Firefox and press F12 to open developer tools.
  2. Go to the Network tab and reload the page.
  3. Click the main document, or a CSS or JavaScript file.
  4. Under Response Headers, look for content-encoding. A value of gzip or br (Brotli) means compression is working.

You can also run a command such as curl -I -H “Accept-Encoding: gzip” https://yourdomain.com and look for the same header. If it is there, you do not need to do anything else.

Step 2: Enable GZIP in cPanel

On cPanel hosting with Apache, the easiest method is built in:

  1. Log in to cPanel.
  2. In the Software section, open Optimize Website.
  3. Choose Compress all content, or Compress the specified MIME types and list text types such as text/html text/plain text/css application/javascript application/json image/svg+xml.
  4. Click Update Settings, then test again.

On LiteSpeed servers, compression is normally handled by the web server itself. On Tremhost cPanel web hosting, which runs LiteSpeed, check the response headers first; you will usually find compression already active.

Step 3: Enable GZIP on Apache with .htaccess

If you do not have cPanel’s tool, add rules to the .htaccess file in your site’s root folder. Back up the file first. The rules use Apache’s mod_deflate module and look like this:

  • <IfModule mod_deflate.c>
  • AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
  • AddOutputFilterByType DEFLATE application/javascript application/json application/xml
  • AddOutputFilterByType DEFLATE image/svg+xml font/ttf font/otf
  • </IfModule>

The IfModule wrapper means the rules are skipped safely if mod_deflate is not installed, instead of causing a server error. Save the file and test again.

Step 4: Enable GZIP on Nginx

On a VPS running Nginx, add these directives to the http block of nginx.conf, or to your site’s server block:

  • gzip on;
  • gzip_comp_level 5;
  • gzip_min_length 256;
  • gzip_vary on;
  • gzip_types text/plain text/css application/javascript application/json application/xml image/svg+xml;

Nginx compresses text/html by default once gzip is on, so it does not need to be listed. Test the configuration with nginx -t, then reload Nginx. A compression level around 5 is a common balance between file size and CPU use.

Step 5: WordPress options

Many caching plugins can turn on compression or add the .htaccess rules for you. On LiteSpeed hosting, use the LiteSpeed Cache plugin, which works with the server. Use only one caching plugin at a time, because overlapping settings can conflict.

If compression still does not show

  • Caching: clear your site cache, any plugin cache and your browser cache, then test again.
  • Wrong file type: check that the file you are testing is a text type you listed, not an image.
  • Very small files: servers often skip files below a minimum size, because compressing them gains nothing.
  • Module missing: if the .htaccess rules have no effect, mod_deflate may not be enabled. Ask your host.

GZIP, Brotli and CDNs

Brotli is a newer compression format that usually produces smaller text files than GZIP. Modern browsers support both, and servers send Brotli when the browser asks for it, falling back to GZIP otherwise. If your site runs behind Cloudflare, Cloudflare compresses responses to visitors itself, so your origin settings matter less for what visitors receive. Tremhost’s Armor service sets up and monitors Cloudflare for you.

Frequently asked questions

How do I know if GZIP compression is enabled?

Check the response headers in your browser’s developer tools. A content-encoding value of gzip or br means compression is on.

Should I compress images with GZIP?

No. JPEG, PNG and WebP are already compressed. Optimise images by resizing them and using efficient formats instead.

Can enabling GZIP break my site?

Rarely. The most common problem is a typing error in .htaccess, which causes a 500 error. Keep a backup and undo the change if that happens.

Is GZIP or Brotli better?

Brotli usually compresses text more. Most servers offer both and pick the best one each browser supports.

Next step

If you want compression, caching and LiteSpeed handled at server level, look at Tremhost web hosting, and test your current site’s headers before you move.

Ask us on WhatsApp