Web hosting · Practical guide

Enable website compression and check the result

Use HTTP headers to check compression, then enable it at the right web server or proxy layer.

A detailed view of website source code

Compression makes text responses smaller before they cross the network. It can help HTML, CSS, JavaScript and similar content, but it will not fix oversized photographs or a slow database.

Check the public response first

Request compression from a text page and inspect the headers. The command below sends Accept-Encoding: gzip. Look for Content-Encoding: gzip in the response rather than assuming a control-panel switch proves it is working.

On your computer: request a compressed response
curl -I -H "Accept-Encoding: gzip" https://example.com

A proxy or CDN may be handling compression already. Some routes are intentionally uncompressed. Test an actual text resource and review the service settings before adding another layer. HEAD responses may differ on unusual applications; inspect a normal browser request too.

Enable it where the response is served

On shared hosting, use the supported hosting option or ask support. Do not place NGINX directives into an Apache .htaccess file. For a self-managed NGINX server, this small example enables gzip for a few common text types.

Example NGINX configuration, not a shell command
gzip on;
gzip_vary on;
gzip_types text/plain text/css application/javascript application/json;

NGINX handles text/html separately. Review existing configuration to avoid duplicate or conflicting settings. Skip formats such as JPEG and ZIP that are already compressed. Consider sensitive authenticated responses separately because compression can have security implications when secrets and reflected input are combined.

Validate before applying the change

On an NGINX VPS, run the configuration test before reloading. Stop and fix any reported error. Only run the reload after the test has succeeded, keeping your backup configuration available.

On the NGINX VPS, one command at a time
sudo nginx -t
sudo systemctl reload nginx

Afterward, repeat the header check from outside the server. Vary: Accept-Encoding helps caches distinguish compressed and uncompressed responses. Review your CDN or caching layer if the public headers do not match the origin settings.

Measure whether it helped

Use the browser Network panel to compare transferred size and loading behavior for the same page. A smaller text response is useful, but images, fonts and third-party scripts may account for much more of the total download.

If waiting for the first byte is still slow, investigate application work and caching. Keep the compression settings simple and documented. The best result is a smaller response with predictable caching and no unnecessary work on the server.

Further reading

← Back to all guidesDiscuss your hosting setup ↗