Reputation: 5933
I have a bookmarklet that keeps using cache versions of http://www.imvu-e.com/products/hpv/download/HPV.js
. I want it to never cache it and always reload it.
This is the hyperlink I use to save the bookmarklet (which users drag to browser toolbar that installs it):
<a href="javascript:(function(){
c = document.createElement("script");
c.type = "text/javascript";
c.src = "http://www.imvu-e.com/products/hpv/download/HPV.js";
c.onload = c.onreadystatechange = function() {
if ( ! (d = this.readyState) || d == "loaded" || d == "complete"){
document.documentElement.childNodes[0].removeChild(c);
version='beta';
}
};
document.documentElement.childNodes[0].appendChild(c);
})();">Run HPV</a>
Upvotes: 7
Views: 18667
Reputation: 1549
Pure JS solution:
<script>
var scr = document.createElement("script");
scr.src = "http://example.com/cool.js" + "?ts=" + new Date().getTime();
document.getElementsByTagName("head")[0].appendChild(scr);
</script>
Upvotes: 2
Reputation: 254
Use jQuery's getScript instead of a script tagging and altering the source
<script>
$.getScript("JavascriptFileName.js?timestamp=" + new Date().getTime());
</script>
Upvotes: 1
Reputation: 7412
Add a useless querystring to the end of your url:
c.src = "http://www.imvu-e.com/products/hpv/download/HPV.js?" + (new Date).getTime();
Upvotes: 19