Created
September 6, 2018 10:45
-
-
Save edmondscommerce/e2259748b084b7668d136458ce84dc6c to your computer and use it in GitHub Desktop.
Quickly test if Cloudflare is caching a resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
readonly DIR=$(dirname $(readlink -f "$0")) | |
cd $DIR; | |
set -e | |
set -u | |
set -o pipefail | |
standardIFS="$IFS" | |
IFS=$'\n\t' | |
usage() { | |
echo "Usage: $0 [URL to test]"; | |
} | |
if (( $# != 1 )); then | |
usage; | |
exit 1; | |
fi | |
readonly url=$1; | |
readonly result=$(curl -I --silent --stderr - "${url}" | grep 'cf-cache-status: HIT'); | |
if [[ -z "${result}" ]]; then | |
echo "Not cached by Cloudflare"; | |
else | |
echo "Cached by Cloudflare"; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment