问题描述
我正在运行一个适用于Chrome和Firefox的简单HTML5应用。它使用Web worker,如下所示:
I am running a simple HTML5 app that works in Chrome and Firefox. It uses a web worker, as in:
var worker = new Worker("the/worker/URL/Code.js");
我在IE中试验了一个多小时,我终于发现网络工作者的代码永远不会重新加载。当我得到它的版本时,抛出一个错误,调试器显示了一个完全过时的工作代码文件版本,即使所有其他文件都已正确重新加载。
I have experimented for over an hour in IE, and I finally found that the web worker's code is never reloaded. When I get the version that it has, to throw an error, the debugger shows me a completely outdated version of the worker code file, even though, all other files have been reloaded properly.
我刷新缓存,使用到处找到的标准建议:安全 - >删除浏览历史 - >选择项目 - >确定 - >等待 - > Ctrl + F5重新加载 - > BAM,调试器仍显示100%与几个小时前相同的文件(请记住,重新加载在Chrome和FF中按预期工作)。
I flushed the cache, using the standard advice found everywhere: Safety -> Delete Browsing History -> Select items -> Ok -> Wait -> Ctrl+F5 to reload -> BAM, thee debugger still shows 100% the same file as several hours ago (remember that reloading works as expected in Chrome and FF).
当我查看网络分析器时,我看到:
When I look at the Network profiler, I see:
URL Protocol Method Result Type Received Taken Initiator Wait Start Request Response Cache read Gap
/js/core/WorkerScriptCode.js (Pending...) GET (Pending...) (Pending...) 0 B (Pending...) webworker 1311 0 0 0 0 31
我不知道为什么会说待定;我可以看到工作者已经运行:我可以看到工作人员的工作已经完成(例如 importScripts
调用显示,还有上面提到的堆栈跟踪)。但它只是运行一个完全过时的版本,即使我将整个缓存刷新了几十次。
I don't know why it says "Pending"; I can see that the worker already runs: I can see the work of the worker being done (e.g. the importScripts
calls show up, and there are also above mentioned stacktraces). But it simply runs a completely outdated version, even though I flushed the entire cache tens of times.
这是一个超级错误,还是我是愚蠢的?
Is this an uber-bug, or am I being stupid?
推荐答案
Chrome中存在同样的问题。为了解决这个问题,您可以使用缓存破解程序:
The same problem exists in Chrome. In order to get around it you can use a cache buster:
主要代码:
var buster = randomNumberOrBuildNumber;
var worker = new Worker( "the/worker/URL/Code.js?buster=" + buster );
工人:
importScripts( 'script/to/import.js' + self.location.search );
这将适用?buster = 12345
(或者你的 randomNumberOrBuildNumber
被设置为)加载工人和任何 importScripts()
调用工人制作。
This will apply ?buster=12345
(or whatever your randomNumberOrBuildNumber
is set to) to both the loading of the worker and any importScripts()
calls the worker makes.
这篇关于Web worker文件被缓存,并且从未在IE 11中重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!