Skip to content

Instantly share code, notes, and snippets.

@lincetto
Forked from imevro/gist:edfe9dea12196056467f
Last active November 15, 2021 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lincetto/2c117d1b5f26380bb41fee2f1783edbf to your computer and use it in GitHub Desktop.
Save lincetto/2c117d1b5f26380bb41fee2f1783edbf to your computer and use it in GitHub Desktop.
Clean up all cached pages in prerender.io from console using a search term
(async () => {
await import('https://code.jquery.com/jquery-2.2.4.min.js')
// Library ready
var cleanUp = function() {
jQuery.ajax({method: "GET", url: "https://dashboard.prerender.io/api/cached-pages?page=0&pageSize=1000&sort=date"}).success(function(response) {
var total = response,
lastChecked = 1;
console.log("total: " + response.length);
for(var i = 0; i < total.length; i++) {
jQuery.ajax({
method: "DELETE",
url: "https://dashboard.prerender.io/api/remove-cached-urls",
data: "{\"urls\":[{\"url\":\"" + total[i].url + "\",\"adaptiveType\":\"desktop\"}]}",
contentType: "application/json;charset=UTF-8",
headers: {
"x-xsrf-token": "<your-token-grabbed-from-a-valid-request>"
}
}).done(function() {
console.log("good, " + (lastChecked + "/" + total.length))
})
}
})
}
cleanUp()
//if you have to remove more than 1k pages, use setInterval
//setInterval(function(){ cleanUp(); }, 15000);
})()
_page = 0;
(async () => {
await import('https://code.jquery.com/jquery-2.2.4.min.js')
// Library ready
var cleanUp = function() {
console.log("recaching from " + (_page * 1000) + " to " + ((_page+1) * 1000));
jQuery.ajax({method: "GET", url: "https://dashboard.prerender.io/api/cached-pages?page="+_page+"&pageSize=1000&sort=date"}).success(function(response) {
var total = response,
lastChecked = 1;
console.log("total: " + response.length);
for(var i = 0; i < total.length; i++) {
jQuery.ajax({
method: "POST",
url: "https://dashboard.prerender.io/api/v2/cache-page",
data: "{\"urls\":[{\"url\":\"" + total[i].url + "\",\"adaptiveType\":\"desktop\"}]}",
contentType: "application/json;charset=UTF-8",
headers: {
"x-xsrf-token": "<your-token-grabbed-from-a-valid-request>"
}
}).done(function() {
console.log("good, " + (lastChecked + "/" + total.length))
})
}
})
}
cleanUp()
//if you have to remove more than 1k pages, use setInterval
//setInterval(function(){ cleanUp(); _page += 1; }, 15000);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment