/**
* Reliably adds a cache bust param to the url
* @param url: string
* @returns string
*/
function cacheBust(url) {
const urlObject = new URL(url, window.location.origin);
const paramsObject = new URLSearchParams(urlObject.search);
paramsObject.set("cacheBust", (new Date().getTime()).toString(36));
return `${urlObject.origin}${urlObject.pathname}?${paramsObject.toString()}`;
}
cacheBust("http://localhost:8000")
// 'http://localhost:8000/?cacheBust=kydo6sdz'
cacheBust("/hello?existing=true")
// 'https://gist.github.com/hello?existing=true&cacheBust=kydo7i52'