Last active
September 29, 2026 16:47
-
-
Save nullthoughts/57b28f1519463b1e6c1d101d11ed1cf5 to your computer and use it in GitHub Desktop.
A small zsh function that checks time to first byte (TTFB) on one host across multiple paths. Pass the host and the relative URLs, and it prints the status code, TTFB, and total time for each. The output is plain text, so you can paste it straight into an issue, a Slack thread, or Claude.
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
| # ttfb — quick TTFB checks for multiple paths on one host. Paste-ready output. | |
| # | |
| # Install: add to ~/.zshrc (or source this file), then run: source ~/.zshrc | |
| # Usage: ttfb example.com /up /products /about | |
| # Auth: TTFB_AUTH='user:pass' ttfb example.com / | |
| # | |
| # Defaults to https:// and tests / when no paths are given. | |
| # Colors: status (2xx green, 3xx yellow, 4xx/5xx red), TTFB (<300ms green, <800ms yellow, slower red) | |
| ttfb() { | |
| local host=${1%/}; shift | |
| [[ $host == http* ]] || host="https://$host" | |
| echo "$host" | |
| local p code first total sc tc | |
| for p in "${@:-/}"; do | |
| read code first total <<< $(curl ${TTFB_AUTH:+-u$TTFB_AUTH} -o /dev/null -s \ | |
| -w "%{http_code} %{time_starttransfer} %{time_total}" "$host$p") | |
| if [[ -t 1 ]]; then | |
| (( code < 300 )) && sc=green || { (( code < 400 )) && sc=yellow || sc=red } | |
| (( first < 0.3 )) && tc=green || { (( first < 0.8 )) && tc=yellow || tc=red } | |
| print -P " $p → %F{$sc}$code%f, TTFB %F{$tc}${first}s%f, total ${total}s" | |
| else | |
| echo " $p → $code, TTFB ${first}s, total ${total}s" | |
| fi | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment