Skip to content

Instantly share code, notes, and snippets.

@rubenvarela
Last active February 27, 2018 23:37
Show Gist options
  • Save rubenvarela/dee4b1ac7e8a8714270ea5b21131c534 to your computer and use it in GitHub Desktop.
Save rubenvarela/dee4b1ac7e8a8714270ea5b21131c534 to your computer and use it in GitHub Desktop.
Bookmarklet to add or increase a query string by 1 (cachebuster). Useful when using caching layers that respect query strings (Cloudflare, Varnish)
javascript:void((function () {
var uri = location.href;
var key = "cachebuster";
var re = new RegExp("([?&])" + key + "=(.*)?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
var matches = uri.match(re);
if (matches) {
location.href = uri.replace(re, '$1' + key + "=" + String(parseInt(matches[2])+1) + '$3');
} else {
location.href = uri + separator + key + "=0";
}
})());
@rubenvarela
Copy link
Author

Expanded this function, https://stackoverflow.com/a/6021027

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