205

I have a webapp on a NGinx server. I set gzip on in the conf file and now I'm trying to see if it works. YSlow says it's not, but 5 out of 6 websites that do the test say it is. How can I get a definite answer on this and why is there a difference in the results?

Johnny
  • 7,073
  • 9
  • 46
  • 72

8 Answers8

280

It looks like one possible answer is, unsurprisingly, curl:

$ curl http://example.com/ --silent --write-out "%{size_download}\n" --output /dev/null
31032
$ curl http://example.com/ --silent -H "Accept-Encoding: gzip,deflate" --write-out "%{size_download}\n" --output /dev/null
2553

In the second case the client tells the server that it supports content encoding and you can see that the response was indeed shorter, compressed.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
zoul
  • 102,279
  • 44
  • 260
  • 354
  • 5
    This is true, but gzip can be configured to compress certain file types, and exclude others. So be sure that the files you curl using this test are of the type that will be compressed. – Tyler Biscoe Oct 24 '13 at 15:26
  • 10
    I would suggest using `-L` flag for `curl` too to follow all redirects, e.g. from non-www to `www.` otherwise result of size_download may be wrong – vladkras Nov 21 '16 at 10:12
  • 1
    If I could impress one thing on my younger devs, its the importance of having a solid unix foundation. +1 for CURL. Its confusing at first, a life saver when you know it. – Akron Apr 12 '19 at 17:43
159

Update

Chrome changed the way it reports (see original answer if interested). You can tell using Developer Tools (F12). Go to the Network tab, select the file you want to examine and then look at the Headers tab on the right. If you are gzipped, then you will see that in the Content-Encoding.

In this example, slider.jpg is indeed being gzipped.

enter image description here

Compare that to this very page that you are on and look at a png file, you will see no such designation.

enter image description here

Just to be clear, it isn't because one is a jpg and one is a png. It is because one is gzipped and the other one isn't.


Previous Answer

In Chrome, if you pull up the Developer Tools and go to the Network tab, then it will show the following if there is no compression:

enter image description here

And the following if there IS compression:

enter image description here

In other words, the same number, top and bottom, means no compression.

Software Prophets
  • 2,838
  • 3
  • 21
  • 21
  • 3
    It may be better to inspect the response headers. This method does not say whether gzip compression is begin used or some other compression algorithm. – Samuel Apr 28 '14 at 20:30
  • 4
    In Chrome Developer Tools on the Network tab, click on the asset name/link for the request and you can inspect the Response Headers like so and see `gzip` for the Content-Encoding key ![screenshot][1] [1]: http://i.stack.imgur.com/Bpb5W.png(http://content.screencast.com/users/Ryan.Regalado/folders/Jing/media/401debfc-d82e-41de-8212-1865ffa2a502/00000352.png) – d48 Aug 04 '14 at 18:39
  • 4
    The recent chrome versions (Version 44.0.2403.130 m) do not seem to show the size/content details - I mean the gzip details - http://i.imgur.com/MTz7DCM.png. Does anyone know the reason why? – Andy Dufresne Aug 12 '15 at 08:57
35

See in the response headers. In FireFox you may check with Firebug.

Content-Encoding    gzip

If server supports gzip content then this should be displayed.

Neeku
  • 3,646
  • 8
  • 33
  • 43
Ved
  • 8,577
  • 7
  • 36
  • 69
  • 9
    You only get this if your client has sent "Accept-Encoding: gzip,deflate" – Maciej Swic Jul 10 '12 at 14:11
  • 2
    Hard refresh to see the original file's encoding, as when the file is served with status 304, it seems that the cached version is already unzipped! (in my case, I'm seeing an ETag header rather than Content-Encoding) – ptim Sep 23 '14 at 08:06
20

In new version of chrome, Developer tools > network, you can right click on Column name, and select content-encoding option and add that column (black box in image).

and if you want to see the size of that gzip content, as @Outfast Source - than you can click on icon which is next to View (displayed as Green box in image).

so you can see which content is gzip enabled.

enter image description here

Krupall
  • 379
  • 3
  • 7
11

You could quickly use a web service like: http://www.whatsmyip.org/http-compression-test/

Google Chrome's "Audits" tool in the developer tools comes in handy as well.

Michael Balint
  • 2,255
  • 4
  • 25
  • 27
9

I wrote this script based on the zoul's answer:

#!/bin/bash

URL=$1
PLAIN="$(curl $URL --silent --write-out "%{size_download}\n" --output /dev/null)"
GZIPPED="$(curl $URL --silent -H "Accept-Encoding: gzip,deflate" --write-out "%{size_download}\n" --output /dev/null)"

if test $PLAIN -gt $GZIPPED
then echo "supported"
else echo "unsupported"
fi

example:

$ ./script.sh https://example.com/
Nate Symer
  • 2,185
  • 1
  • 20
  • 27
2

Here's my one-liner:

curl https://google.com --silent -L -H "Accept-Encoding: gzip,deflate" --output testFile && file testFile

The file command line tool tells you what type of file it is. You should see this:

testFile: gzip compressed data, max compression, original size modulo 2^32 13926
pietrorea
  • 841
  • 6
  • 14
0

since it's first search result in google, I'm going to edit one the answers to include Brotli compression too, its short name is br and you can use it with curl or watch for it via F12 in browser.

for curl edited from @zoul answer:

$ curl http://example.com/ --silent --write-out "%{size_download}\n" --output /dev/null
31032
$ curl http://example.com/ --silent -H "Accept-Encoding: gzip,deflate,br" --write-out "%{size_download}\n" --output /dev/null
2553
danronmoon
  • 3,814
  • 5
  • 34
  • 56