These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:05 pm Advanced search

web worker's baseUrl

Do you think the HTML spec should do something differently? You can discuss spec feedback here, but you should send it to the WHATWG mailing list or file a bug in the W3C bugzilla for it to be considered.

web worker's baseUrl

Postby fmate14 » Tue May 25, 2010 2:02 pm

* What is the problem you are trying to solve?
The worker's base URL is it's path:
Code: Select all
index.html
scripts
   \-- worker.js
modules
   \-- myModule.js

If my module can work with or without worker, I must use
Code: Select all
<script src="modules/myModule.js" />
in html, but
Code: Select all
importScripts('../modules/myModule.js')
in worker.

It will be good to import scripts relative to the main document, not the worker. Like in PHP's require() or import().

* What is the feature you are suggesting to help solve it?
Code: Select all
var worker = new Worker('scriptFile.js', 'baseURL');

or
Code: Select all
var worker = new Worker('scriptFile.js',{baseUrl:'baseUrl'});


* What is the processing model for that feature, including error handling?
It doesn't change.

* Why do you think browsers would implement this feature?
It is easy to implement.

* Why do you think authors would use this feature?
It is more intuitive, than the current solution.

* What evidence is there that this feature is desparately needed?
There is no evidence. I am not sure, that this is a good idea. What do you think?

I have created a framework, which must load itself first. But if it is no beside the html nor the other scripts, the developer don't know, how can he import scripts with relative url, so I must convert every url to absolute url.

Sorry my english.
fmate14
<h6>
 
Posts: 1
Joined: Tue May 25, 2010 1:38 pm

Postby zcorpan » Tue May 25, 2010 3:18 pm

I think the reason for this is that a worker can be shared between several documents.

You could work around this by doing something like:

Code: Select all
var worker = new Worker('scripts/worker.js#../');

Code: Select all
var base = location.hash.substr(1);
importScripts(base + 'modules/myModule.js');
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden

Postby zcorpan » Tue May 25, 2010 3:20 pm

Also URLs can be relative against the root by using '/' as the first character, as in:

Code: Select all
importScripts('/foo/bar/modules/myModules.js');
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden

Postby wihitmult » Wed Feb 16, 2011 8:58 am

Yes URL can be use using the “/â€
wihitmult
<h6>
 
Posts: 1
Joined: Wed Feb 16, 2011 8:34 am


Return to Feedback on the Specs

Who is online

Users browsing this forum: No registered users and 1 guest