Skip to content

Instantly share code, notes, and snippets.

@imevro
Last active January 6, 2021 05:19
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save imevro/edfe9dea12196056467f to your computer and use it in GitHub Desktop.
Save imevro/edfe9dea12196056467f to your computer and use it in GitHub Desktop.
Clean up all cached pages in prerender.io from console
var cleanUp = function() {
$.ajax({method: "GET", url: "https://prerender.io/api/cached-pages?page=0&pageSize=1000000"}).success(function(response) {
var total = response,
lastChecked = 1;
console.log("total: " + response.length);
for(var i = 0; i < total.length; i++) {
$.ajax({
method: "DELETE",
url: "https://prerender.io/api/remove-cached-url?url=" + encodeURIComponent (total[i].url)
}).done(function() {
console.log("good, " + (lastChecked + "/" + total.length))
})
}
})
}
cleanUp()
@benjamincerigo
Copy link

Hey I needed to put the x-xsrf-token: to get the authorization to work.

@mholding
Copy link

mholding commented Oct 3, 2018

How did you find out about these rest endpoints? is there a doc somewhere?

@jwh315
Copy link

jwh315 commented Dec 15, 2018

thanks for this, the delete call needs a csrf header now. You can get the csrf token by inspecting a valid delete request in the console

headers: {
    "x-xsrf-token": "token from prerender"
}

I also had an issue deleting any more than 1000 domains at a time. Cloudflare started throttling my requests. I ended up coming up with this implementation to delete all the domains synchronously without getting blocked by cloudflare

@osdiab
Copy link

osdiab commented Jan 6, 2021

I also made a quick implementation here that's simple and calculates the CSRF token properly: https://gist.github.com/osdiab/71b0cd8c5c7385e816130e9d597ec4cd

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