简体   繁体   中英

can a Web Workers file handle includes or modules?

I have several web worker s, each supporting different tables in the database. Each of web worker uses a core set of functions (for accessing the server, querying, etc).

What is the best means for putting these shared, common fuctions into the several web worker s?

it seems that if they are loaded as files, then the browser will have them cached and the workers themselves can be lighter.

perhaps they could be loaded as es6 modules .

Web workers receive a global function, importScripts ( spec | MDN ), that you can use to import scripts into the worker's global context:

importScripts('shared.js');

Someday, I'm sure we'll be able to use ES2015 (ES6) modules, but that day will likely be at least a year or two from now. :-)

另请注意, RequireJS适用于Web工作者,因此如果您将其用于应用程序,则可以轻松解决依赖关系问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM