How to check if gzip is enabled
Ask for gzip and read the header: curl -s -H 'accept-encoding: gzip' -D - -o /dev/null https://example.com/. A content-encoding: gzip line means the server compressed the body. Then request the same URL with accept-encoding: identity and compare %{size_download}, because the header alone never tells you how many bytes it saved.
Checker offline. Follow the manual steps below, they give the same answer.
Why check this
Compression is a server configuration, so it survives no deployment by itself. A release that moves a route behind a new reverse proxy, or a rewrite that starts serving HTML from an application server instead of the CDN, turns gzip off for that route while every other route stays compressed. Run this on staging sign-off for each content type the release touched. The failure it prevents is a page that ships at four times its usual weight and shows up two weeks later as a mobile timeout report with no code change to blame.
Prerequisites
- curl 7.21 or later. gzip needs no build flag, so the curl already on your machine works. See the curl manual.
- A URL that returns text. Images, fonts and video are already compressed and a sane server skips them.
- The MDN page on Content-Encoding for the token list.
Steps
- Step 1.
Ask for gzip only, and print the response headers without the body.
curl -s -H 'accept-encoding: gzip' -D - -o /dev/null https://www.cloudflare.com/ | grep -i -E '^HTTP|content-encoding|vary'HTTP/2 103 HTTP/2 200 vary: accept-encoding content-encoding: gzipThe
103line is an early hints response. Read the headers under the200. - Step 2.
Measure the uncompressed body.
identityis the token for "send it raw".curl -s -o /dev/null -H 'accept-encoding: identity' -w '%{size_download}\n' https://www.cloudflare.com/1317143 - Step 3.
Measure the same body with gzip.
%{size_download}counts bytes off the wire, so this is the compressed size.curl -s -o /dev/null -H 'accept-encoding: gzip' -w '%{size_download}\n' https://www.cloudflare.com/2945771317143 against 294577 is a ratio of 4.5 to 1 for this HTML document. Expect the number to move by a few hundred bytes between runs, because the origin recompresses each response.
- Step 4.
Run the negative control. A route with no compression answers the same request like this.
curl -s -H 'accept-encoding: gzip' -D - -o /dev/null https://httpbin.org/html | grep -i -E '^HTTP|content-encoding|content-length'HTTP/2 200 content-length: 3741No
content-encodingat all. That is the shape of a failure, and knowing it stops you reading an empty grep as a broken command.
How to read the result
| What you see | What it means | What to do |
| --- | --- | --- |
| content-encoding: gzip and the byte count drops | gzip is on for this route | Nothing. Record the ratio so the next release has a baseline. |
| No content-encoding, byte counts equal | The route is uncompressed | Check the route, not the whole service. Compression is usually per location block. |
| content-encoding: br | The server preferred brotli | gzip may still be configured. Ask for gzip alone, as in step 1. |
| Header present, byte counts equal | A proxy sets the header without compressing | Report it. Clients that decode the body will fail on the raw bytes. |
| content-encoding: gzip on a JPEG or a ZIP | Wasted CPU on both ends | Exclude the type at the server. The body gets no smaller and often grows. |
Common mistakes
Thresholds
What to check next
- How to check if brotli is enabled: brotli beats gzip on the same document, and a server that has both picks brotli for browsers.
- How to check content-encoding: the header itself, including the case where it is absent and the case where it says identity.
- How to check vary header: without it a shared cache can hand your gzipped body to a client that cannot read it.
- How to check HTTP response headers with curl: the general form of the command used above.
- Gzip compression test: runs the same comparison per resource type and prints the sizes.
FAQ
How much does gzip compress a page?
On the Cloudflare home page measured here, 1317143 bytes fell to 294577, a ratio of 4.5 to 1. HTML and JSON with repeated markup compress hardest. Minified JavaScript lands nearer 3 to 1. Measure your own document rather than quoting a ratio.
How to test gzip compression with curl?
Steps 1 to 3 are the test. Send accept-encoding: gzip, read content-encoding, then repeat with accept-encoding: identity and compare %{size_download}. Two numbers and one header line settle it.
How to check gzip compression in Chrome?
Open DevTools, Network tab, click the request, then the Headers panel for content-encoding. The Size column shows transferred bytes over decoded bytes. A DevTools capture of the MDN CORS page on this machine read 30865 bytes transferred against 258732 decoded.
How to check if an API supports gzip?
Send the same header to the API route. Compression on the HTML does not imply it on JSON. https://httpbin.org/json returned content-length: 429 with no content-encoding when asked for gzip, which is what an uncompressed API looks like.
Verified
Verified by Maks Vernycurl 8.21.0
Each output block is what the command above it printed on that date, on the host named in the step. Figures read from a live site move between runs. Compare the shape of the answer rather than the digits, and see the methodology for how a page is re-verified.
Related on this site
- Checker: compression content-encoding per resource type, size before and after
- Web performance checklist
- Website launch checklist
- All performance and delivery checks
basic4 minpublished updated Maks Verny