Can I load a web worker script from an absolute URL?

前端 未结 3 1007
说谎
说谎 2020-12-10 20:53

I haven\'t been able to get something like this to work:

var myWorker = new Worker(\"http://example.com/js/worker.js\");

In my Firebug cons

相关标签:
3条回答
  • 2020-12-10 21:34

    Not to mention...

    Just about anytime you have a Cross-Origin Restriction Policy, there's no counterpoise to the file system (file://path/to/file.ext) - Meaning, the file protocol triggers handling for this policy.

    This goes for "dirty images" in the Canvas API as well.

    Hope this helps =]

    0 讨论(0)
  • 2020-12-10 21:42

    For those that don't know, here is the spec for Web Worker: http://www.whatwg.org/specs/web-workers/current-work/

    And a post by John Resig: http://ejohn.org/blog/web-workers/

    Javascript, generally, can't access anything outside of the url that the javascript file came from.

    I believe that is what this part of the spec means, from: http://www.w3.org/TR/workers/

    4.2 Base URLs and origins of workers

    Both the origin and effective script origin of scripts running in workers are the origin of the absolute URL given in that the worker's location attribute represents.

    This post has a statement about what error should be thrown in your situation: http://canvex.lazyilluminati.com/misc/cgi/issues.cgi/message/%3Cop.u0ppu4lpidj3kv@zcorpandell.linkoping.osa%3E

    0 讨论(0)
  • 2020-12-10 21:48

    According to the Web Worker draft specification, workers must be hosted at the same domain as the "first script", that is, the script that is creating the worker. The URL of the first script is what the worker URL is resolved against.

    0 讨论(0)
提交回复
热议问题