applicationCache 是“未定义”的;在共享网络工作者 (HTML5) 中

发布于 2024-10-01 02:46:40 字数 1515 浏览 10 评论 0原文

我正在尝试访问 的离线应用程序缓存共享 webworker (HTML5) 没有运气。我已经为这个问题绞尽脑汁好几个小时了,所以我一定错过了一些东西......来自 JavaScript Ninja 的任何帮助都将受到高度赞赏!

W3C 规范 指出:(

cache = self.applicationCache

在共享工作线程)应返回适用于当前共享工作线程的 ApplicationCache 对象。

我通过以下方式从我的应用程序的主脚本中生成一个共享工作人员:

var worker = new SharedWorker('js/test.js');
worker.port.addEventListener('message', function(e) {
    alert('got message: ' + e.data);
}, false);
worker.port.start();
worker.port.postMessage('hi there...');

这是我的共享工作人员的代码 (test.js):

var cache = self.applicationCache;

onconnect = function(e) {
    var port = e.ports[0];
    port.onmessage = function(e) {
        // test.html contains a <html manifest='test.manifest'> tag 
        var xmlHttp = new XMLHttpRequest();
        xmlHttp.open("GET", "test.html", false);
        xmlHttp.send(null);
        var result = xmlHttp.responseText;
        port.postMessage(result);
        port.postMessage('cache: '+ cache);
}

}

我收到的警报是:

  1. test.html 的内容(如我所料)
  2. 消息“缓存:未定义”(哎呀!)

我在 Google Chrome 7.0.517.44 和 Safari 5.0.2 (Mac OS X 10.6.4) 上尝试过此操作。我还尝试在访问缓存和许多其他变体之前触发 HTTP GET,但所有这些尝试都得到相同的结果。

我错过了一些明显的东西吗?这是我测试过的浏览器的已知限制吗?

非常感谢,

奥里

I'm trying to access the offline application cache of a shared webworker (HTML5) with no luck. I've been banging my head against this problem for many hours, so I must be missing something... Any help from a JavaScript Ninja out there would be highly appreciated!

The W3C the spec says that:

cache = self.applicationCache

(in a shared worker) should return the ApplicationCache object that applies to the current shared worker.

I'm spawning a shared worker from my app's main script via:

var worker = new SharedWorker('js/test.js');
worker.port.addEventListener('message', function(e) {
    alert('got message: ' + e.data);
}, false);
worker.port.start();
worker.port.postMessage('hi there...');

And here's the code of my shared worker (test.js):

var cache = self.applicationCache;

onconnect = function(e) {
    var port = e.ports[0];
    port.onmessage = function(e) {
        // test.html contains a <html manifest='test.manifest'> tag 
        var xmlHttp = new XMLHttpRequest();
        xmlHttp.open("GET", "test.html", false);
        xmlHttp.send(null);
        var result = xmlHttp.responseText;
        port.postMessage(result);
        port.postMessage('cache: '+ cache);
}

}

The alerts I'm getting are:

  1. the contents of test.html (as I expected)
  2. the message "cache : undefined" (oops!)

I tried this on Google Chrome 7.0.517.44 and Safari 5.0.2 (Mac OS X 10.6.4). I also tried to trigger the HTTP GET before accessing the cache and many other variations, but all of these attempts resulted with the same outcome.

Am I missing something obvious? Is this is a known limitations of the browsers I've tested?

Many Thanks,

Ori

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白馒头 2024-10-08 02:46:40

我发现了同样的事情 - 虽然说实话,我什至不确定为什么我们想要访问 applicationCache 对象...我认为这只是缓存的东西?!不管怎样 - 当我试图让它工作时,我发现这个线程正在谈论它:

http://lists.w3.org/Archives/Public/public-webapps/2009OctDec/0519.html

我认为我可以直接粘贴并输入主页的cache.manifest文件引用了工作文件,它会神奇地填充 applicationCache。但它似乎并没有(我只是像你一样未定义)。

在 w3c 规范的处理模型部分中,它说:

如果工作程序全局范围实际上是 SharedWorkerGlobalScope 对象(即工作程序是共享工作程序),并且存在由具有相同来源的清单 URL 标识的任何相关应用程序缓存作为 url 并且将 url 作为其条目之一(不排除标记为外部的条目),然后将工作器全局范围与匹配的最合适的应用程序缓存相关联。

但我无法让它发挥作用!

I found the same thing - though to be honest, I'm not even sure WHY we'd want access to the applicationCache object... I thought it just, cached things?! Anyway - when I was trying to get it to work I found this thread talking about it:

http://lists.w3.org/Archives/Public/public-webapps/2009OctDec/0519.html

I assumed that I could just stick and entry in my cache.manifest file of the main page that referenced the worker file and it would populate the applicationCache magically. But it didn't appear to (I just got undefined like you did).

In the w3c spec, in the Processing Model section it says:

If worker global scope is actually a SharedWorkerGlobalScope object (i.e. the worker is a shared worker), and there are any relevant application caches that are identified by a manifest URL with the same origin as url and that have url as one of their entries, not excluding entries marked as foreign, then associate the worker global scope with the most appropriate application cache of those that match.

But I can't make it work!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文