How to Tell if a Webpage Can Also Be Delivered Gzipped - Command Line With Curl
Overview
First of all, why would you want to have Gzipped content? Let’s have a look at the HTTP protocol to understand how this works and then the command to test it is working.
Understanding gzip compression is also an important factor when analyzing web-pages with speed measurement tools like Google’s PageSpeed Insights, as it has a special Enable Compression rule to detect that compressible resources were served with compression, and get rid of the following message:
Enable compression
Compressing resources with gzip or deflate can reduce the number of bytes sent over the network.
Theory
The HTTP protocol has the capability to transfer compressed content, this improves transfer speed and bandwidth utilization.
Negotiation in HTTP goes like this:
First the web client, makes a request to the server notifying which compression schemes it supports. This is done by including a list of tokens in the HTTP request. Compression in HTTP can be done in two ways:
- Transfer-Encoding header field:
- Used at lower level.
- Field:
TE
.
- Content-Encoding header:
- Used at higher level and the most common one.
- Field:
Accept-Encoding
. Example:Accept-Encoding: gzip, deflate
- Transfer-Encoding header field:
If the server supports any of the requested methods, it delivers the compressed data using
Content-Encoding
orTransfer-Encoding
field in the HTTP response with the used schemes. - Example:Content-Encoding: gzip
Browsers that do not support compliant compression method will download data without compression.
The most common compression schemes include gzip, Deflate and Brotli.
Commands
The command line utility we use to test for gzip compression is
curl
, a flexible tool to transfer data from a server.
To just get the header info, we use the -I
parameter. (equivalent to
--head
)
$ curl -I http://example.com
Which gives us:
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Sat, 18 Aug 2018 18:04:04 GMT
Etag: "1541025663"
Expires: Sat, 25 Aug 2018 18:04:04 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (mic/9B22)
X-Cache: HIT
Content-Length: 1270
Note the above Content-Length
of 1270.
So now we test the web page was served using compression, including
the Content-Encoding header
in the request with the -H
parameter:
$ curl -I http://example.com -H "Accept-Encoding: gzip,deflate"
And expect to have Content-Encoding
in the response:
HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Sat, 18 Aug 2018 18:04:32 GMT
Etag: "1541025663+gzip"
Expires: Sat, 25 Aug 2018 18:04:32 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (mic/9A89)
X-Cache: HIT
Content-Length: 606
Content-Length
is 606, which gives us a content that is 48% the size
of the uncompressed page size.
To just get the web page download size of the compressed and uncompressed content:
$ curl http://example.com/ --silent -H "Accept-Encoding: gzip,deflate" --write-out "%{size_download}\n" --output /dev/null 606 $ curl http://example.com/ --silent --write-out "%{size_download}\n" --output /dev/null 1270
Also if your web-pages are effectively using gzip
compression, in
PageSpeed Insights you will get the following message: Enable
compression: You have compression enabled.
References
- https://en.wikipedia.org/wiki/HTTP_compression
- https://developers.google.com/speed/docs/insights/EnableCompression
- https://tools.ietf.org/html/rfc2616
- How can I tell if my server is serving GZipped content?
- Save audio from Google Translator in 6 steps in Ubuntu Linux THE RIGHT WAYJune 9, 2022
- How to Tell if a Webpage Can Also Be Delivered Gzipped - Command Line With Curl
- Colors Palettes For Web DesignDecember 9, 2016
- Script to automatically tweet new blog posts based in a website RSS feedNovember 10, 2016
Basic HTML concepts
- Minify Html in your static website (Hugo or Jekyll)August 15, 2018
- Checklist for website developers about performance, SEO and general webmaster's considerationsApril 3, 2017
- How To Check Local Websites For Broken LinksNovember 1, 2016
- Appropriate HTML5 tags to show source code, commands and software related tasks on blogsJuly 22, 2016
HTML cheatsheets
- Html5 Full CheatsheetJune 4, 2016
Responsive Web Design
- HTML viewport meta tag for responsive designsJune 21, 2016
Hostings
- Redirect HTTP to HTTPS and WWW to non-WWW with AWS S3, Cloudfront and Route 53 with a custom domainApril 22, 2017
Search Engine Optimization
- Essential Seo Tips And Techniques From Trusted SourcesJanuary 26, 2017
Structured Data Markups
Web Servers
Apache HTTP Server
Nginx Server
- Secure Nginx ServerAugust 30, 2018
- Redirect Www to Non Www With NginxAugust 30, 2018
Articles
Subcategories
Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.
Powered by SimpleIT Hugo Theme
·