Skip to content

Instantly share code, notes, and snippets.

@tdtgit

tdtgit/warmupv3.sh

Created May 16, 2020
Embed
What would you like to do?
#!/bin/bash
DOMAIN=$1
scan_sitemap () {
[ -z "$1" ] && URL="https://$DOMAIN/sitemap.xml" || URL=$1
curl -L --compressed $URL 2>/dev/null | grep -Eo "http(s?):\/\/$DOMAIN[^ \"\'()\<>]+" | while read line; do
if [[ $line = *.xml ]]
then
echo "👉 Sitemap $line"
scan_sitemap $line
else
if [[ $line =~ .*.(jpg|gif|png)$ ]]
then
image_warmup $line
else
url_warmup $line
fi
fi
done;
}
url_warmup () {
echo " 🏋️ Warming brotli $1"
curl -sSL -H 'accept-encoding: br' -A 'The Boring Cache Warmer' $1 -o /dev/null &
echo " 🏋️ Warming non-brotli $1"
curl -sSL -H 'accept-encoding: gzip' -A 'The Boring Cache Warmer' $1 -o /dev/null
echo -e " ✅ Done\n"
}
image_warmup () {
echo " 🏋️ Warming WEBP $1"
curl -sSL -H 'accept: image/webp,image/apng,image/*,*/*;q=0.8' -A 'The Boring Cache Warmer' $1 -o /dev/null &
echo " 🏋️ Warming non-WEBP $1"
curl -sSL -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -A 'The Boring Cache Warmer' $1 -o /dev/null &
echo -e " ✅ Done\n"
}
scan_sitemap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.