Skip to content

Instantly share code, notes, and snippets.

@tdtgit
Created May 16, 2020 15:41
Show Gist options
  • Save tdtgit/9ff4c4e8af347111cf22e9425aff2405 to your computer and use it in GitHub Desktop.
Save tdtgit/9ff4c4e8af347111cf22e9425aff2405 to your computer and use it in GitHub Desktop.
#!/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