Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active Aug 11, 2020
Embed
What would you like to do?
Recursive PURGE from BASE URL for Fastly

Requirements

  • wget
  • curl

Usage

$ bash fastly-recursive-purge.sh https://example.com

$ curl -sL https://gist.github.com/tkuchiki/d988e30cd67de136d1752adbd82cac96/raw/d24c78ee99b1fb9e69d3639882de3e120358c0e1/fastly-recursive-purge.sh | bash -s https://example.com
#!/bin/bash
base_url="${1}"
[ "${base_url}" = "" ] && echo "\$1(base URL) is required" && exit 1
purge_url() {
local url="${1}"
curl -s -X PURGE ${url}
echo "purged ${url}"
sleep 0.1
}
for url in $(LANG=C wget -p -nv -nd -r --spider ${base_url} -o /dev/stdout | grep URL | sed -e 's/URL://' | awk '{print $3}'); do
purge_url "${url}"
[[ "${url}" =~ /$ ]] && purge_url "${url}index.html"
done
@bigtiger
Copy link

bigtiger commented Aug 11, 2020

🌈

We nearly used this for a project I was working on. In our case we were able to use Surrogate Keys to tag all the content we needed purged and then make a single call to the API to instruct Fastly to purge all content tagged with that key.

Leaving this note for future travelers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment