Skip to content

Improving Website Speed with NGINX Caching and Compression

NGINX · Self-help guide

NGINX can help websites feel faster by reducing unnecessary work and sending smaller responses to visitors. Two common performance features are compression and caching. Compression makes text-based files smaller during transfer, while caching can store responses so NGINX does not need to ask the backend application for every single request.

Compression is useful for HTML, CSS, JavaScript, JSON, and XML. On many Ubuntu setups, gzip can be enabled in the main NGINX configuration. After enabling or adjusting gzip settings, always test:

sudo nginx -t sudo systemctl reload nginx

Caching is more advanced. You can cache static files easily by setting browser cache headers for images, fonts, CSS, and JavaScript. For backend applications, proxy caching can be used carefully, but you must avoid caching private pages, user dashboards, checkout pages, admin panels, or anything that changes per visitor.

Step-by-step safe performance approach:

  1. Start with static file caching.
  2. Enable compression.
  3. Test website pages in a browser.
  4. Check application logins and forms still behave normally.
  5. Only add full-page or proxy caching when you understand what should and should not be cached.

Useful commands:

curl -I https://example.com sudo nginx -t sudo tail -f /var/log/nginx/error.log

The curl -I command is useful because it shows response headers, including cache-control, content-encoding, and server responses.

Performance tuning should be done carefully. A faster website is great, but broken logins or stale content are not. Make one change at a time, test properly, and keep a backup of your working configuration before adding advanced caching rules.

Did this solve it?If not, Penny and the support team are ready to help.Start live chatOpen a ticket