A Step-by-Step Guide To Setting Up Gzip Compression

A fast website has less work to do before a page becomes useful. Gzip compression reduces the size of text-based files such as HTML, CSS, JavaScript, XML and JSON, allowing browsers to download them more quickly. The server compresses a response, the browser receives it, and the browser decompresses it automatically.

This can improve loading performance on busy Australian networks, where visitors may connect from a fibre service in Melbourne, a mobile connection in Sydney, or a slower regional link outside Brisbane. Smaller transfers also reduce bandwidth consumption, which matters for both hosting budgets and users with limited mobile data.

Gzip is most valuable when files contain repeated text patterns. A stylesheet with many similar selectors or a JavaScript bundle with recurring variable names can shrink substantially. Images, videos and most modern font formats usually need different treatment because they are already compressed.

The setup is straightforward when you know which server delivers your files. The process involves checking current behaviour, enabling compression, excluding unsuitable file types, testing the response headers and monitoring the result. A clean resource hub such as SpeedTao can also help teams keep performance documentation and support information easy to find.

Check Whether Compression Is Already Active

Before changing configuration, inspect the website’s current response. Browser developer tools can show whether a document or asset was served with a Content-Encoding: gzip header. Open the Network panel, select a CSS or JavaScript request, and compare the transferred size with the uncompressed resource size.

Online performance tools can provide a second opinion, although their result may vary according to the test location and requested URL. Test the production domain rather than a staging address, and check several resource types. A page may compress HTML correctly while serving an uncompressed JavaScript bundle.

You should also identify the web server or hosting platform. Apache, Nginx, LiteSpeed, managed WordPress hosting and static hosting providers each expose compression through different controls. If the site sits behind a content delivery network, compression may be handled at the edge rather than by the origin server.

Prepare The Files And MIME Types

Gzip works with text-based content. Common candidates include text/html, text/plain, text/css, text/javascript, application/javascript, application/json, application/xml and image/svg+xml. SVG files are text documents, so they often respond well to compression even though their file extension suggests an image.

Avoid applying Gzip to JPEG, PNG, GIF, WebP, AVIF, MP4, PDF and compressed archive files. Recompressing these formats adds processor work without producing a meaningful reduction. Some font files, such as WOFF2, are already highly compressed and normally should be left alone.

Correct MIME types are important because server rules often compress by content type rather than file extension. A JavaScript file incorrectly delivered as text/plain may still be compressed, but it signals a configuration problem worth fixing. Accurate types also help browsers interpret resources consistently.

Enable Gzip On Apache

Apache commonly uses mod_deflate for response compression. On a server where the module is available, an administrator can enable it with a command such as a2enmod deflate, then reload Apache. Shared hosting customers may need to place rules in an .htaccess file instead.

A basic .htaccess configuration can look like this:

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

The exact syntax can vary with the Apache version and hosting environment. Keep the rule limited to suitable text formats, and avoid adding broad file-extension rules that might compress archives or media unnecessarily. After updating the file, clear any server or CDN cache so the new response can be observed.

Apache may also need a Vary: Accept-Encoding header. This tells caches that the response differs depending on whether the browser accepts compressed content. Modern modules commonly manage this header automatically, but it is worth checking during testing.

Enable Gzip On Nginx

Nginx handles compression in its server or HTTP configuration. A typical block includes gzip on, a minimum response size and a list of text MIME types:

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

The gzip_min_length setting prevents very small responses from receiving compression where the headers and processing could outweigh the saving. A moderate compression level is generally a sensible starting point. Higher levels can reduce files slightly further while consuming more CPU, which may be counterproductive on a busy virtual server.

After editing Nginx, validate the configuration before reloading it:

sudo nginx -t
sudo systemctl reload nginx

If the site is delivered through a reverse proxy or CDN, check which layer is responsible. Enabling Gzip at both layers is usually safe because the outer layer can recognise an already compressed response, but a poorly configured proxy can create cache variation or incorrect headers.

Configure Compression On Static Hosting

Static site platforms frequently provide automatic Gzip or Brotli compression. If the service generates compressed variants during deployment, there may be no server file to edit. Instead, check the platform’s documentation and inspect a live asset after publishing.

For a generated site, compression should be paired with sensible asset handling. Minify CSS and JavaScript, create cache-friendly filenames such as app.4f82c.js, and avoid shipping development source maps to ordinary visitors unless they are required. A useful reference on building efficient generated websites is this Hugo performance guide.

Australian organisations often use managed hosting to reduce administration across offices in Sydney, Melbourne and Perth. That convenience can be valuable when staff need a reliable publishing workflow rather than direct access to server configuration. Ask the provider whether compression is enabled at the origin, CDN or both, and whether cache invalidation occurs after deployment.

Test Headers, Size And Browser Behaviour

Use curl to request a page while declaring support for Gzip:

curl -I -H "Accept-Encoding: gzip" https://example.com/

A successful response should include Content-Encoding: gzip for an eligible text resource and usually Vary: Accept-Encoding. The Content-Type header should accurately describe the content. For a more practical comparison, request the body and inspect transfer statistics:

curl -H "Accept-Encoding: gzip" -o /dev/null \
  -s -w "Downloaded: %{size_download}\n" https://example.com/styles.css

Use browser developer tools to compare transferred and decoded sizes. Test an uncached request as well as a repeat visit, because a cached result may hide changes. Examine HTML, CSS, JavaScript and JSON separately, then test from more than one network.

This matters across Australia’s varied connectivity. A visitor using a Telstra, Optus or Vodafone mobile connection may notice reduced transfer sizes sooner than someone on a fast office link. A user in Perth requesting content from an eastern-state server may also benefit from fewer bytes travelling across a long route, even though compression does not remove network latency.

Maintain Compression Without Creating Problems

Compression is one part of a wider performance routine. Keep an eye on server CPU, time to first byte, cache hit rates and real-user loading measurements. If CPU usage rises sharply after enabling a high compression level, lower the level or allow a CDN to handle the work.

Set cache headers alongside compression. Long-lived caching works well with versioned static assets, while HTML usually needs a shorter lifetime so new releases appear promptly. Ensure the CDN does not cache a Gzip response and deliver it to a client that did not advertise support for Gzip.

Recommended operating practices include:

Gzip remains a dependable compatibility layer, while Brotli can provide smaller results for many web assets when the platform supports it. The practical aim is not to compress every byte at any cost. It is to deliver suitable content efficiently, preserve correct caching behaviour and make the site feel responsive for visitors from Adelaide to Darwin as well as major metropolitan centres.