Check GZip Encoding with curl

By  on  

Last week I detailed how I enabled gzip encoding on nginx servers, the same server software I use on this site.  Enabling gzip on your server exponentially improves the site load time, thus improving user experience and (hopefully) Google page ranks.  I implemented said strategy and used another website to check if the gzip encoding worked, but little did I know, you can use the curl utility check if the encoding update worked.  Here's how you can check if the gzip encoding worked:

curl -H "Accept-Encoding: gzip" -I https://davidwalsh.name

After executing the shell command, you'll get a response that looks like this:

HTTP/1.1 200 OK
Server: nginx
Date: Mon, 21 Jul 2014 01:12:36 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 20
Connection: keep-alive
X-Pingback: https://davidwalsh.name/xmlrpc.php
Cache-Control: max-age=1, private, must-revalidate
Expires: Mon, 21 Jul 2014 01:12:37 GMT
X-Powered-By: PleskLin
MS-Author-Via: DAV
Vary: Accept-Encoding
Content-Encoding: gzip

From the above response, you can see that the page was served gzipped via the Content-Encoding: gzip header.  You can check individual files instead of pages to ensure they have been gzipped as well.  The amount of effort you put into gzipping your site is worth it -- imagine how fast it makes your site to the thousands and millions of visitors you have each day!

Recent Features

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

  • By
    How to Create a RetroPie on Raspberry Pi – Graphical Guide

    Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices.  While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo...

Incredible Demos

  • By
    GitHub-Style Sliding Links

    GitHub seems to change a lot but not really change at all, if that makes any sense; the updates come often but are always fairly small. I spotted one of the most recent updates on the pull request page. Links to long branch...

  • By
    DWRequest: MooTools 1.2 AJAX Listener & Message Display

    Though MooTools 1.2 is in its second beta stage, its basic syntax and theory changes have been hashed out. The JavaScript library continues to improve and become more flexible. Fellow DZone Zone Leader Boyan Kostadinov wrote a very useful article detailing how you can add a...

Discussion

  1. Spencer

    You can also use the --compressed flag.

  2. Another great tool is: http://checkgzipcompression.com/
    Same thing but a very pretty graphic output.

  3. Aravind

    You can also try this:

    curl -k --compressed -o mydata.txt "https://url"
    
  4. https://api.cryptomkt.com/v1/order"
       -H "X-MKT-APIKEY:  "
       -H "X-MKT-SIGNATURE:  "
       -H "X-MKT-TIMESTAMP:  "
       -X POST
    
  5. Wasin

    To be able to see “text” data from gzipped content use the following (as found here https://stackoverflow.com/a/18984239/571227)

    curl -sH 'Accept-encoding: gzip' http://example.com/ | gunzip -
  6. Chris

    This didn’t work for me. It worked for some sites, but not for others that I knew for sure, had gzip enabled. The problem is the -I option. It sends a HEAD request. Try this, it worked with all sites:

    curl -sD - -o /dev/null https://example.com
    

    https://stackoverflow.com/a/26644485/960857

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!