Created
April 20, 2025 23:06
-
-
Save maesoser/8396cc12045beb45117541a81df7b3a9 to your computer and use it in GitHub Desktop.
sitespeed
This file contains hidden or 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 | |
function sitespeed { | |
docker run --rm \ | |
-v "$1" \ | |
--add-host=${2}:${3} \ | |
sitespeedio/sitespeed.io:33.6.1 "$4" \ | |
--outputFolder /home/chrome/reports \ | |
--plugins.add analysisstorer \ | |
--summary-detail \ | |
--browsertime.iterations 10 \ | |
--crawler.depth 1 \ | |
--gzipHAR | |
} | |
URL=$1 | |
if [ -z "$URL" ]; then | |
echo -e "Usage:\n\tsitespeed <filename>" | |
exit | |
fi | |
URL=$(echo "http://${URL}" | tr -d '\r\n' | tr -d '\n') | |
DOMAIN=$(echo ${URL} | awk -F[/:] '{print $4}') | |
echo -e "Testing $URL" | |
RESOLVED=$2 | |
if [ -z "$RESOLVED" ]; then | |
echo -e "[WARN] ${YELLOW}No resolve override supplied, resolving${DOMAIN}" | |
RESOLVED=$(dig +short @1.0.0.1 $DOMAIN | tail -n1) | |
fi | |
echo -e "[INFO] Domain $DOMAIN resolves to $RESOLVED$" | |
OUTPUT="$(pwd)/results/$DOMAIN/$RESOLVED" | |
DOCKERVOL="${OUTPUT}:/home/chrome/reports" | |
echo "Creating output folder: ${OUTPUT}" | |
mkdir -p $OUTPUT | |
PREFLIGHT=$(curl -skI "$URL" -w '%{response_code};%{redirect_url}\n' -o /dev/null) | |
CODE=$(echo "$PREFLIGHT" | cut -d";" -f1) | |
if [[ "$CODE" == "301" ]]; then | |
URL=$(echo "$PREFLIGHT" | cut -d";" -f2 | tr -d '\r\n' | tr -d '\n') | |
echo -e "[${CODE}] Redirection detected to $URL" | |
fi | |
sitespeed ${DOCKERVOL} ${DOMAIN} ${RESOLVED} ${URL} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment