Closed tgvashworth closed 10 years ago
The first implementation sounds like the best thing. However, importScripts
should throw if it's called after the initial execution of worker.
importScripts
shouldn't make a network request once the serviceworker has installed, imported scripts should be put in a special cache.
Related: https://github.com/slightlyoff/ServiceWorker/issues/106
Seems like the best method here would be a combination of both:
importScripts
URLsBut, this isn't such a great method if you want to prevent it being called later.
The parsing trick falls over with importScripts(variable)
.
What's the benefit of calling importScripts
later than initial execution?
Not sure what you mean – you can get the variable out no problem.
The problem with not doing an AST parse is that, afaik, there's no way to pause function execution while node does a network request and have the fetched code execute in the same scope as the worker.
Not sure what you mean – you can get the variable out no problem.
var whatever = 'foo';
if (version > 4) {
whatever = 'bar';
}
importScripts(whatever);
or
importScripts(whatever + Math.random());
The problem with not doing an AST parse is that, afaik, there's no way to pause function execution while node does a network request and have the fetched code execute in the same scope as the worker.
Oh, there isn't a way to make a sync network request? Sheeeeet
You're not going to like it, but here's how the xmlhttprequest lib does sync requests https://github.com/driverdan/node-XMLHttpRequest/blob/master/lib/XMLHttpRequest.js#L454
Eurgh, yeah. Fair enough. @ahume's working on this atm.
Think this is more or less there. Reopen if not.
Implementation options:
importScripts
or
importScripts
method just key a URL -> result map.Second one for me.