Skip to content
quarry Artifact [de8e205ee1]
Login

Artifact [de8e205ee1]

Artifact de8e205ee1c553bf5db7422780aab68c6605ea44e50c89ee01accd3bbdab0da7:


#!/bin/sh
# wire-check: what a first visit to a page actually costs on the wire.
# Fetches the page, follows every /assets/ link it carries, and prints
# raw size, wire size, encoding and cache policy per file — the numbers
# to look at after a deploy, or before arguing about a minifier.
#   scripts/wire-check.sh https://zeitforge.app/fleet/exceptions
set -eu
page="${1:?usage: wire-check.sh URL}"
base=$(printf '%s' "$page" | sed -E 's#^(https?://[^/]+).*#\1#')
ua='Mozilla/5.0 quarry-wire-check'
row() {
  url=$1
  hdr=$(curl -sSL -D - -o /tmp/wire.$$ -H "User-Agent: $ua" -H 'Accept-Encoding: br, gzip' "$url")
  wire=$(wc -c < /tmp/wire.$$ | tr -d ' ')
  enc=$(printf '%s' "$hdr" | awk 'tolower($1)=="content-encoding:"{print $2}' | tr -d '\r'); enc=${enc:-identity}
  cache=$(printf '%s' "$hdr" | awk 'tolower($1)=="cache-control:"{$1="";print}' | tr -d '\r' | sed 's/^ //')
  raw=$(curl -sSL -o /dev/null -w '%{size_download}' -H "User-Agent: $ua" -H 'Accept-Encoding: identity' "$url")
  printf '%-40s raw %8s  wire %8s  %-8s  %s\n' "$(basename "$url" | cut -c1-40)" "$raw" "$wire" "$enc" "${cache:--}"
  rm -f /tmp/wire.$$
}
row "$page"
curl -sSL -H "User-Agent: $ua" --compressed "$page" | grep -o '/assets/[^"]*' | sort -u | while read -r a; do row "$base$a"; done