Created
June 3, 2013 18:21
-
-
Save mcrumley/5700157 to your computer and use it in GitHub Desktop.
Gets a unique URL to avoid browser cache
This file contains hidden or 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
function cache_buster(url) { | |
cache_buster.nonce = cache_buster.nonce || 1; | |
var sep = "?"; | |
var qpos = url.indexOf("?"); | |
if (url.length === 0 || qpos === url.length-1) { | |
sep = ""; | |
} else if (qpos >= 0) { | |
sep = "&"; | |
} | |
return url + sep + "nocache=" + (new Date()).getTime() + "-" + cache_buster.nonce++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment