url-lib
Version:
A simple, lightweight string utility for Node and browsers that supports serializing and parsing URLs and query strings.
21 lines (17 loc) • 744 B
JavaScript
// Adapted from the Uize.Url module, a part of the UIZE JavaScript Framework.
var cacheDefeatStrCallCount = 0;
/**
* Returns a string value (generated using the time and a random number)
* that can be used as a query parameter value to cause a URL to be
* unique in order to defeat caching.
* @returns {string} Cache defeat string
*/
var getCacheDefeatStr = function getCacheDefeatStr() {
// Three pieces of randomness:
// current timestamp
var timestamp = Date.now(); // random number between 1-1000
var randomNum = Math.round(Math.random() * 1000); // continuously incrementing counter
var counter = cacheDefeatStrCallCount++;
return "".concat(timestamp).concat(randomNum).concat(counter);
};
export default getCacheDefeatStr;