Skip to content

Instantly share code, notes, and snippets.

@domtronn
Created February 3, 2022 10:38
Show Gist options
  • Save domtronn/2d539cd880450ef234c9af8411a2fc2b to your computer and use it in GitHub Desktop.
Save domtronn/2d539cd880450ef234c9af8411a2fc2b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# This script compares the different compression & download times of a cdn using the `Accept-Encoding` header
# It will compare Brotli, Gzip, and uncompressed responses
#
# ./compare-compress.sh https://my-url.com
set -euo pipefail
URL=$1
function gzip() {
URL="$1"
printf "%-40s" "gzipped, $URL"
curl -so /dev/null $URL -H "Accept-Encoding: gzip" -w '%{size_download}, Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total}\n'
}
function brotli() {
URL="$1"
printf "%-40s" "brotli, $URL"
curl -so /dev/null $URL -H "Accept-Encoding: br" -w '%{size_download}, Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total}\n'
}
function uncompressed() {
URL="$1"
printf "%-40s" "uncompressed, $URL"
curl -so /dev/null $URL -H "Accept-Encoding:" -w '%{size_download}, Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total}\n'
}
uncompressed $URL
gzip $URL
brotli $URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment