小工具实时图像(Internet Explorer)缓存 [英] Gadget live image (Internet Explorer) caching

查看:66
本文介绍了小工具实时图像(Internet Explorer)缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经通过网络流为本地广播电台创建了一个小型广播播放器。

I've created tiny radio player for local radio station, via web stream.

我是开发了一个弹出窗口,显示播放的最后一首歌,这是他们服务器上的.jpeg / gif(这有关系吗?)。似乎他们会以某种方式自动更新它。

I've developed a flyout, showing last song played, which is a .jpeg/gif (does it matter?) on their server. Seems they automatically update it somehow.

我的问题是,(IE?)缓存该图像,所以仍然显示来自(示例)16:32的歌曲,其中19 :50。

My side of problem is, that (IE?) caches that image, so song from (example,) 16:32 is still shown, and its 19:50.

是否有JS代码可刷新图像,但禁用缓存?

Is there a JS code which would refresh the image, but disabling cache?

推荐答案

尝试向网址添加虚拟参数。

Try adding a dummy parameter to the URL.

如果您的现有网址已经有参数,您可以使用类似...

If your existing URL already has parameters you could use something like ...

function addUpdateParameter(refreshCacheInterval){
 var result, now=new Date().getTime();
 result=(refreshCacheInterval)?(refreshCacheInterval*1000):1;
 return "&uniq="+(now-(now%result));
}

...如果现有的网址没有任何参数,只需更改第一个字符即可来自"&"的返回值到"?"喜欢...

...if the existing URL does not have any parameters, just change the first character of the return value from "&" to "?" like...

function addUpdateParameter(refreshCacheInterval){
 var result, now=new Date().getTime();
 result=(refreshCacheInterval)?(refreshCacheInterval*1000):1;
 return "?uniq="+(now-(now%result));
}

然后使用上面的内容:

myURL = myURL + addUpdateParameter(300);

myURL = myURL + addUpdateParameter(300);

传递给addUpdateParameter函数的值是以秒为单位的时间,在此之后将生成新的返回值。如果,如上所述,您使用300,那么新的返回值将每五分钟生成一次,并且在此时间内将使用缓存

The value you pass to the addUpdateParameter function is the time in seconds after which a new return value will be generated. If, as above, you used 300 then a new return value will only be generated once every five minutes and inside of this time cache will be used.

如果省略传递一个值,如:

If you omit to pass a value like :

myURL = myURL + addUpdateParameter();

myURL = myURL + addUpdateParameter();

然后每次都会生成一个新的返回值。

then a new return value will be generated every time.

有时您可能想要使用缓存 - 这样您就可以将传递给函数的值作为另一个表达式的结果。

Sometimes you might want to use the cache - this way you can make the value you pass to the function the result of another expression.

有时您可能总是想要使用缓存,您可以使用另一个表达式来决定是否使用该函数。

Sometimes you might always want to use cache and you can use another expression to decide whether to use the function at all.


这篇关于小工具实时图像(Internet Explorer)缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆