2012-02-22 90 views
4

我有一个书签,继续使用缓存版本http://www.imvu-e.com/products/hpv/download/HPV.js。我希望它永远不会缓存它,并始终重新加载它。如何强制使用javascript和基本脚本加载缓存

这是我用来保存书签(其中用户拖动到其安装浏览器工具栏)的超级链接:

<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> 
+0

js/html ..的混合很糟糕使用一个js框架 – dynamic 2012-02-22 17:32:54

+2

@ yes123这是一个书签,你应该把一个体面的块在网址(因为它需要执行加载你的更复杂的js文件) – wheresrhys 2012-02-22 17:57:04

回答

15

一个无用的查询字符串添加到您的网址的结尾:

c.src = "http://www.imvu-e.com/products/hpv/download/HPV.js?" + (new Date).getTime(); 
+0

+1,但它应该是日期.getTime() – wheresrhys 2012-02-22 17:57:46

+0

@wheresrhys谢谢,更新。 – Prescott 2012-02-22 18:11:20

+9

必须使用'c.src =“http://www.imvu-e.com/products/hpv/download/HPV.js?” + new Date()。getTime();' – ParoX 2012-02-22 18:51:54

0

使用jQuery的getScript代替脚本标记和更改源文件

<script> 
    $.getScript("JavascriptFileName.js?timestamp=" + new Date().getTime()); 
</script> 
+3

我正在撰写SO评论,因为您的答案已被标记为其质量。在回答时,请注意您的答案将来可能会被多次阅读。这使得在他们中写入解释性注释变得很重要。请您花一两分钟编辑您的答案,并附上一些文字,说明您的答案如何以及为何提供了解决方案? – 2017-04-18 20:39:49