How to force no cache using javascript and basic s

2019-02-17 15:17发布

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(&quot;script&quot;);
     c.type = &quot;text/javascript&quot;;
     c.src = &quot;http://www.imvu-e.com/products/hpv/download/HPV.js&quot;;

     c.onload = c.onreadystatechange = function()                    {
            if ( ! (d = this.readyState) || d == &quot;loaded&quot; || d == &quot;complete&quot;){
                document.documentElement.childNodes[0].removeChild(c);
                version='beta';
            }
     };
     document.documentElement.childNodes[0].appendChild(c);
})();">Run HPV</a>

2条回答
小情绪 Triste *
2楼-- · 2019-02-17 15:59

Use jQuery's getScript instead of a script tagging and altering the source

<script>
   $.getScript("JavascriptFileName.js?timestamp=" + new Date().getTime());
</script>
查看更多
欢心
3楼-- · 2019-02-17 16:10

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(); 
查看更多
登录 后发表回答