Last active
February 27, 2018 23:37
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
})()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expanded this function, https://stackoverflow.com/a/6021027