Reputation: 20203
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
.
Upvotes: 3
Views: 1128
Reputation: 53119
Also note that RequireJS
works in web workers so if you use that for your app, you can easily have dependencies resolved.
Upvotes: 1
Reputation: 1074028
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. :-)
Upvotes: 1